Mappings: Generate dynamic mappings for empty strings.

This will help the exists/missing filters behave as expected in presence of
empty strings, as well as when using a default analyzer that would generate
tokens for an empty string (uncommon).

Close #8198
This commit is contained in:
Adrien Grand 2014-11-03 16:17:21 +01:00
parent ab0bee47c5
commit 3501e32dce
2 changed files with 9 additions and 5 deletions

View File

@ -739,11 +739,6 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
}
}
if (!resolved && context.parser().textLength() == 0) {
// empty string with no mapping, treat it like null value
return;
}
if (!resolved && context.root().dateDetection()) {
String text = context.parser().text();
// a safe check since "1" gets parsed as well

View File

@ -20,8 +20,10 @@ package org.elasticsearch.index.mapper.dynamic;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMappers;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.StrictDynamicMappingException;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Test;
@ -147,4 +149,11 @@ public class DynamicMappingTests extends ElasticsearchSingleNodeTest {
// all is well
}
}
public void testDynamicMappingOnEmptyString() throws Exception {
IndexService service = createIndex("test");
client().prepareIndex("test", "type").setSource("empty_field", "").get();
FieldMappers mappers = service.mapperService().indexName("empty_field");
assertTrue(mappers != null && mappers.isEmpty() == false);
}
}