use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.
the class DocumentParserTests method testDynamicStrictLongArray.
public void testDynamicStrictLongArray() 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").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.bytes.BytesReference in project elasticsearch by elastic.
the class DocumentParserTests method testDynamicDottedFieldNameObjectWithParentTemplate.
public void testDynamicDottedFieldNameObjectWithParentTemplate() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startArray("dynamic_templates").startObject().startObject("georule").field("match", "foo*").startObject("mapping").field("type", "object").endObject().endObject().endObject().endArray().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.bytes.BytesReference in project elasticsearch by elastic.
the class DocumentParserTests method testMappedGeoPointArray.
public void testMappedGeoPointArray() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo").field("type", "geo_point").field("doc_values", false).endObject().endObject().endObject().endObject().string();
DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
BytesReference bytes = XContentFactory.jsonBuilder().startObject().startArray("foo").startArray().value(0).value(0).endArray().startArray().value(1).value(1).endArray().endArray().endObject().bytes();
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
assertEquals(2, doc.rootDoc().getFields("foo").length);
}
use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.
the class DocumentParserTests method testDynamicObjectWithTemplate.
public void testDynamicObjectWithTemplate() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startArray("dynamic_templates").startObject().startObject("georule").field("match", "foo*").startObject("mapping").field("type", "object").startObject("properties").startObject("bar").field("type", "keyword").endObject().endObject().endObject().endObject().endObject().endArray().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(2, doc.rootDoc().getFields("foo.bar").length);
}
use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.
the class DocumentParserTests method testMappedNullValue.
public void testMappedNullValue() throws Exception {
DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo").field("type", "long").endObject().endObject().endObject().endObject().string();
DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
BytesReference bytes = XContentFactory.jsonBuilder().startObject().field("foo", (Long) null).endObject().bytes();
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
assertEquals(0, doc.rootDoc().getFields("foo").length);
}
Aggregations