[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.

This commit is contained in:
Martijn van Groningen 2014-03-26 14:34:18 +07:00
parent 6354bc4861
commit 2c65711dd9
3 changed files with 44 additions and 2 deletions

View File

@ -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"));
}
}

View File

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