use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.
the class DocumentParserTests method testDynamicStrictValue.
public void testDynamicStrictValue() 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("bar", "baz").endObject().bytes();
StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, () -> mapper.parse("test", "type", "1", bytes));
assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage());
}
use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.
the class DocumentParserTests method testDynamicDottedFieldNameLong.
public void testDynamicDottedFieldNameLong() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
BytesReference bytes = XContentFactory.jsonBuilder().startObject().field("foo.bar.baz", 0).endObject().bytes();
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
assertEquals(2, doc.rootDoc().getFields("foo.bar.baz").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(NumberFieldMapper.class));
}
use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.
the class DocumentParserTests method testDynamicFalseDottedFieldNameLong.
public void testDynamicFalseDottedFieldNameLong() 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().field("foo.bar.baz", 0).endObject().bytes();
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
assertEquals(0, doc.rootDoc().getFields("foo.bar.baz").length);
}
use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.
the class DocumentParserTests method testPropagateDynamicWithDynamicMapper.
public void testPropagateDynamicWithDynamicMapper() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", false).startObject("properties").startObject("foo").field("type", "object").field("dynamic", true).startObject("properties").endObject().endObject().endObject().endObject().endObject().string();
DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
BytesReference bytes = XContentFactory.jsonBuilder().startObject().startObject("foo").startObject("bar").field("baz", "something").endObject().endObject().endObject().bytes();
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
assertNotNull(doc.dynamicMappingsUpdate());
assertNotNull(doc.rootDoc().getField("foo.bar.baz"));
}
use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.
the class CopyToMapperTests method testCopyToDynamicNestedObjectParsing.
public void testCopyToDynamicNestedObjectParsing() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startArray("dynamic_templates").startObject().startObject("objects").field("match_mapping_type", "object").startObject("mapping").field("type", "nested").endObject().endObject().endObject().endArray().startObject("properties").startObject("copy_test").field("type", "text").field("copy_to", "very.inner.field").endObject().endObject().endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
BytesReference json = jsonBuilder().startObject().field("copy_test", "foo").field("new_field", "bar").endObject().bytes();
try {
docMapper.parse("test", "type1", "1", json).rootDoc();
fail();
} catch (MapperParsingException ex) {
assertThat(ex.getMessage(), startsWith("It is forbidden to create dynamic nested objects ([very]) through `copy_to`"));
}
}
Aggregations