From f40b72633b0a2c91852aabc1688b4e4125c97c81 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 23 Dec 2015 17:45:46 +0100 Subject: [PATCH] Add sub-fields support to `bool` fields. `bool` is our only core mapper that does not support sub fields. Close #6587 --- .../index/mapper/core/BooleanFieldMapper.java | 3 +++ .../mapper/core/BooleanFieldMapperTests.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java index d5440f227f4..76f8eb34a71 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java @@ -43,6 +43,7 @@ import java.util.Map; import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue; import static org.elasticsearch.index.mapper.MapperBuilders.booleanField; import static org.elasticsearch.index.mapper.core.TypeParsers.parseField; +import static org.elasticsearch.index.mapper.core.TypeParsers.parseMultiField; /** * A field mapper for boolean fields. @@ -107,6 +108,8 @@ public class BooleanFieldMapper extends FieldMapper { } builder.nullValue(nodeBooleanValue(propNode)); iterator.remove(); + } else if (parseMultiField(builder, name, parserContext, propName, propNode)) { + iterator.remove(); } } return builder; diff --git a/core/src/test/java/org/elasticsearch/index/mapper/core/BooleanFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/core/BooleanFieldMapperTests.java index 2bf97a4885c..3aa04ba0f01 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/core/BooleanFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/core/BooleanFieldMapperTests.java @@ -28,6 +28,7 @@ import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -110,4 +111,27 @@ public class BooleanFieldMapperTests extends ESSingleNodeTestCase { builder.endObject(); assertEquals("{\"field\":{\"type\":\"boolean\",\"doc_values\":false,\"null_value\":true}}", builder.string()); } + + public void testMultiFields() throws IOException { + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startObject("properties") + .startObject("field") + .field("type", "boolean") + .startObject("fields") + .startObject("as_string") + .field("type", "string") + .field("index", "not_analyzed") + .endObject() + .endObject() + .endObject().endObject() + .endObject().endObject().string(); + DocumentMapper mapper = indexService.mapperService().merge("type", new CompressedXContent(mapping), true, false); + assertEquals(mapping, mapper.mappingSource().toString()); + BytesReference source = XContentFactory.jsonBuilder() + .startObject() + .field("field", false) + .endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", source); + assertNotNull(doc.rootDoc().getField("field.as_string")); + } }