Browse Source

[TEST] Added extra test for multi fields with default `include_in_all` settings, in which only the main field should end up in the `_all` field.

Martijn van Groningen 11 years ago
parent
commit
2c65711dd9

+ 23 - 2
src/test/java/org/elasticsearch/index/mapper/all/SimpleAllMapperTests.java

@@ -284,8 +284,8 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
     }
 
     @Test
-    public void testMultiField() throws IOException {
-        String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/multifield-mapping.json");
+    public void testMultiField_includeInAllSetToFalse() throws IOException {
+        String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/multifield-mapping_include_in_all_set_to_false.json");
         DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
 
         XContentBuilder builder = XContentFactory.jsonBuilder();
@@ -302,4 +302,25 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
         AllEntries allEntries = ((AllTokenStream) field.tokenStream(docMapper.mappers().indexAnalyzer())).allEntries();
         assertThat(allEntries.fields(), empty());
     }
+
+    @Test
+    public void testMultiField_defaults() throws IOException {
+        String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/multifield-mapping_default.json");
+        DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
+
+        XContentBuilder builder = XContentFactory.jsonBuilder();
+        builder.startObject()
+                .field("_id", "1")
+                .field("foo")
+                .startObject()
+                .field("bar", "Elasticsearch rules!")
+                .endObject()
+                .endObject();
+
+        Document doc = docMapper.parse(builder.bytes()).rootDoc();
+        AllField field = (AllField) doc.getField("_all");
+        AllEntries allEntries = ((AllTokenStream) field.tokenStream(docMapper.mappers().indexAnalyzer())).allEntries();
+        assertThat(allEntries.fields(), hasSize(1));
+        assertThat(allEntries.fields(), hasItem("foo.bar"));
+    }
 }

+ 21 - 0
src/test/java/org/elasticsearch/index/mapper/all/multifield-mapping_default.json

@@ -0,0 +1,21 @@
+{
+    "test": {
+        "properties": {
+            "foo": {
+                "type": "nested",
+                "properties": {
+                    "bar": {
+                        "type": "string",
+                        "index": "not_analyzed",
+                        "fields": {
+                            "lower": {
+                                "analyzer": "standard",
+                                "type": "string"
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

+ 0 - 0
src/test/java/org/elasticsearch/index/mapper/all/multifield-mapping.json → src/test/java/org/elasticsearch/index/mapper/all/multifield-mapping_include_in_all_set_to_false.json