From 3501e32dce3d834534e6d7a69523b2986182a7d6 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Mon, 3 Nov 2014 16:17:21 +0100 Subject: [PATCH] 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 --- .../elasticsearch/index/mapper/object/ObjectMapper.java | 5 ----- .../index/mapper/dynamic/DynamicMappingTests.java | 9 +++++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java index 7699fbd166b..bfafa5212d0 100644 --- a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java @@ -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 diff --git a/src/test/java/org/elasticsearch/index/mapper/dynamic/DynamicMappingTests.java b/src/test/java/org/elasticsearch/index/mapper/dynamic/DynamicMappingTests.java index 459e35d8e80..5af8f9823e5 100644 --- a/src/test/java/org/elasticsearch/index/mapper/dynamic/DynamicMappingTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/dynamic/DynamicMappingTests.java @@ -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); + } } \ No newline at end of file