use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class DocumentParserTests method testDynamicDottedFieldNameObjectWithExistingParent.
public void testDynamicDottedFieldNameObjectWithExistingParent() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo").field("type", "object").endObject().endObject().endObject().endObject().string();
DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
BytesReference bytes = XContentFactory.jsonBuilder().startObject().startObject("foo.bar.baz").field("a", 0).endObject().endObject().bytes();
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz.a").length);
Mapper fooMapper = doc.dynamicMappingsUpdate().root().getMapper("foo");
assertNotNull(fooMapper);
assertThat(fooMapper, instanceOf(ObjectMapper.class));
Mapper barMapper = ((ObjectMapper) fooMapper).getMapper("bar");
assertNotNull(barMapper);
assertThat(barMapper, instanceOf(ObjectMapper.class));
Mapper bazMapper = ((ObjectMapper) barMapper).getMapper("baz");
assertNotNull(bazMapper);
assertThat(bazMapper, instanceOf(ObjectMapper.class));
Mapper aMapper = ((ObjectMapper) bazMapper).getMapper("a");
assertNotNull(aMapper);
assertThat(aMapper, instanceOf(NumberFieldMapper.class));
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class DocumentParserTests method testTypeLevelWithFieldTypeAsValueNotFirst.
public void testTypeLevelWithFieldTypeAsValueNotFirst() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().startObject("type").field("test1", "value1").field("type", "value_type").field("test2", "value2").startObject("inner").field("inner_field", "inner_value").endObject().endObject().endObject().bytes());
assertThat(doc.rootDoc().get("type.type"), equalTo("value_type"));
assertThat(doc.rootDoc().get("type.test1"), equalTo("value1"));
assertThat(doc.rootDoc().get("type.test2"), equalTo("value2"));
assertThat(doc.rootDoc().get("type.inner.inner_field"), equalTo("inner_value"));
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class DocumentParserTests method testTypeLevelWithFieldTypeAsObjectNotFirst.
public void testTypeLevelWithFieldTypeAsObjectNotFirst() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().startObject("type").field("test1", "value1").startObject("type").field("type_field", "type_value").endObject().field("test2", "value2").startObject("inner").field("inner_field", "inner_value").endObject().endObject().endObject().bytes());
assertThat(doc.rootDoc().get("type.type.type_field"), equalTo("type_value"));
assertThat(doc.rootDoc().get("type.test1"), equalTo("value1"));
assertThat(doc.rootDoc().get("type.test2"), equalTo("value2"));
assertThat(doc.rootDoc().get("type.inner.inner_field"), equalTo("inner_value"));
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class DocumentParserTests method testDynamicStrictDottedFieldNameLongArray.
public void testDynamicStrictDottedFieldNameLongArray() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", "strict").endObject().endObject().string();
DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
BytesReference bytes = XContentFactory.jsonBuilder().startObject().startArray("foo.bar.baz").value(0).value(1).endArray().endObject().bytes();
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, () -> mapper.parse("test", "type", "1", bytes));
assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage());
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class DocumentParserTests method testTypeLevelWithFieldTypeAsObject.
public void testTypeLevelWithFieldTypeAsObject() throws Exception {
String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(defaultMapping));
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().startObject("type").startObject("type").field("type_field", "type_value").endObject().field("test1", "value1").field("test2", "value2").startObject("inner").field("inner_field", "inner_value").endObject().endObject().endObject().bytes());
assertThat(doc.rootDoc().get("type.type.type_field"), equalTo("type_value"));
assertThat(doc.rootDoc().get("type.test1"), equalTo("value1"));
assertThat(doc.rootDoc().get("type.test2"), equalTo("value2"));
assertThat(doc.rootDoc().get("type.inner.inner_field"), equalTo("inner_value"));
}
Aggregations