String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/multifield-mapping.json");
DocumentMapper documentMapper = mapperService.documentMapperParser().parse(mapping);
ParsedDocument doc = documentMapper.parse("person", "1", XContentFactory.jsonBuilder()
.startObject()
.field("file", bytes)
.endObject()
.bytes());
assertThat(doc.rootDoc().getField("file"), notNullValue());
assertThat(doc.rootDoc().getField("file").stringValue(), is(originalText + "\n"));
assertThat(doc.rootDoc().getField("file.content_type"), notNullValue());
assertThat(doc.rootDoc().getField("file.content_type").stringValue(), is(contentType));
assertThat(doc.rootDoc().getField("file.content_type.suggest"), notNullValue());
assertThat(doc.rootDoc().getField("file.content_type.suggest").stringValue(), is(contentType));
assertThat(doc.rootDoc().getField("file.content_length"), notNullValue());
assertThat(doc.rootDoc().getField("file.content_length").numericValue().intValue(), is(originalText.length()));
assertThat(doc.rootDoc().getField("file.suggest"), notNullValue());
assertThat(doc.rootDoc().getField("file.suggest").stringValue(), is(originalText + "\n"));
// Let's force some values
doc = documentMapper.parse("person", "1", XContentFactory.jsonBuilder()
.startObject()
.startObject("file")
.field("_content", bytes)
.field("_name", forcedName)
.endObject()
.endObject()
.bytes());
assertThat(doc.rootDoc().getField("file"), notNullValue());
assertThat(doc.rootDoc().getField("file").stringValue(), is(originalText + "\n"));
assertThat(doc.rootDoc().getField("file.content_type"), notNullValue());
assertThat(doc.rootDoc().getField("file.content_type").stringValue(), is(contentType));
assertThat(doc.rootDoc().getField("file.content_type.suggest"), notNullValue());
assertThat(doc.rootDoc().getField("file.content_type.suggest").stringValue(), is(contentType));
assertThat(doc.rootDoc().getField("file.content_length"), notNullValue());
assertThat(doc.rootDoc().getField("file.content_length").numericValue().intValue(), is(originalText.length()));
assertThat(doc.rootDoc().getField("file.suggest"), notNullValue());
assertThat(doc.rootDoc().getField("file.suggest").stringValue(), is(originalText + "\n"));
assertThat(doc.rootDoc().getField("file.name"), notNullValue());
assertThat(doc.rootDoc().getField("file.name").stringValue(), is(forcedName));
// In mapping we have default store:false
assertThat(doc.rootDoc().getField("file.name").fieldType().stored(), is(false));
assertThat(doc.rootDoc().getField("file.name.suggest"), notNullValue());
assertThat(doc.rootDoc().getField("file.name.suggest").stringValue(), is(forcedName));
// In mapping we set store:true for suggest subfield
assertThat(doc.rootDoc().getField("file.name.suggest").fieldType().stored(), is(true));
}