use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class DocumentParserTests method testDynamicFalseObject.
public void testDynamicFalseObject() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", "false").endObject().endObject().string();
DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
BytesReference bytes = XContentFactory.jsonBuilder().startObject().startObject("foo").field("bar", "baz").endObject().endObject().bytes();
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
assertEquals(0, doc.rootDoc().getFields("foo.bar").length);
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class DocumentParserTests method testNoLevelWithFieldTypeAsValue.
public void testNoLevelWithFieldTypeAsValue() 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().field("type", "value_type").field("test1", "value1").field("test2", "value2").startObject("inner").field("inner_field", "inner_value").endObject().endObject().bytes());
assertThat(doc.rootDoc().get("type"), equalTo("value_type"));
assertThat(doc.rootDoc().get("test1"), equalTo("value1"));
assertThat(doc.rootDoc().get("test2"), equalTo("value2"));
assertThat(doc.rootDoc().get("inner.inner_field"), equalTo("inner_value"));
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class DocumentParserTests method testTypeDisabled.
public void testTypeDisabled() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("enabled", false).endObject().endObject().string();
DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
BytesReference bytes = XContentFactory.jsonBuilder().startObject().startObject("foo").field("field", "1234").endObject().endObject().bytes();
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
assertNull(doc.rootDoc().getField("field"));
assertNotNull(doc.rootDoc().getField(UidFieldMapper.NAME));
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class DocumentParserTests method testParseToJsonAndParse.
public void testParseToJsonAndParse() throws Exception {
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
DocumentMapper docMapper = parser.parse("person", new CompressedXContent(mapping));
String builtMapping = docMapper.mappingSource().string();
// reparse it
DocumentMapper builtDocMapper = parser.parse("person", new CompressedXContent(builtMapping));
BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
Document doc = builtDocMapper.parse("test", "person", "1", json).rootDoc();
assertThat(doc.get(docMapper.uidMapper().fieldType().name()), equalTo(Uid.createUid("person", "1")));
assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay"));
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class DocumentParserTests method testDynamicStrictDottedFieldNameLong.
public void testDynamicStrictDottedFieldNameLong() 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().field("foo.bar.baz", 0).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());
}
Aggregations