Search in sources :

Example 86 with CompressedXContent

use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.

the class NestedObjectMapperTests method testMultiObjectAndNested1.

public void testMultiObjectAndNested1() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("nested1").field("type", "nested").startObject("properties").startObject("nested2").field("type", "nested").field("include_in_parent", true).endObject().endObject().endObject().endObject().endObject().endObject().string();
    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    assertThat(docMapper.hasNestedObjects(), equalTo(true));
    ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
    assertThat(nested1Mapper.nested().isNested(), equalTo(true));
    assertThat(nested1Mapper.nested().isIncludeInParent(), equalTo(false));
    assertThat(nested1Mapper.nested().isIncludeInRoot(), equalTo(false));
    ObjectMapper nested2Mapper = docMapper.objectMappers().get("nested1.nested2");
    assertThat(nested2Mapper.nested().isNested(), equalTo(true));
    assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(true));
    assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false));
    ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "value").startArray("nested1").startObject().field("field1", "1").startArray("nested2").startObject().field("field2", "2").endObject().startObject().field("field2", "3").endObject().endArray().endObject().startObject().field("field1", "4").startArray("nested2").startObject().field("field2", "5").endObject().startObject().field("field2", "6").endObject().endArray().endObject().endArray().endObject().bytes());
    assertThat(doc.docs().size(), equalTo(7));
    assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6"));
    assertThat(doc.docs().get(0).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(0).get("field"), nullValue());
    assertThat(doc.docs().get(1).get("nested1.nested2.field2"), equalTo("5"));
    assertThat(doc.docs().get(1).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(1).get("field"), nullValue());
    assertThat(doc.docs().get(2).get("nested1.field1"), equalTo("4"));
    assertThat(doc.docs().get(2).get("nested1.nested2.field2"), equalTo("5"));
    assertThat(doc.docs().get(2).get("field"), nullValue());
    assertThat(doc.docs().get(3).get("nested1.nested2.field2"), equalTo("3"));
    assertThat(doc.docs().get(3).get("field"), nullValue());
    assertThat(doc.docs().get(4).get("nested1.nested2.field2"), equalTo("2"));
    assertThat(doc.docs().get(4).get("field"), nullValue());
    assertThat(doc.docs().get(5).get("nested1.field1"), equalTo("1"));
    assertThat(doc.docs().get(5).get("nested1.nested2.field2"), equalTo("2"));
    assertThat(doc.docs().get(5).get("field"), nullValue());
    assertThat(doc.docs().get(6).get("field"), equalTo("value"));
    assertThat(doc.docs().get(6).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(6).get("nested1.nested2.field2"), nullValue());
}
Also used : CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 87 with CompressedXContent

use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.

the class NestedObjectMapperTests method testMultiRootAndNested1.

public void testMultiRootAndNested1() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("nested1").field("type", "nested").startObject("properties").startObject("nested2").field("type", "nested").field("include_in_root", true).endObject().endObject().endObject().endObject().endObject().endObject().string();
    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    assertThat(docMapper.hasNestedObjects(), equalTo(true));
    ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
    assertThat(nested1Mapper.nested().isNested(), equalTo(true));
    assertThat(nested1Mapper.nested().isIncludeInParent(), equalTo(false));
    assertThat(nested1Mapper.nested().isIncludeInRoot(), equalTo(false));
    ObjectMapper nested2Mapper = docMapper.objectMappers().get("nested1.nested2");
    assertThat(nested2Mapper.nested().isNested(), equalTo(true));
    assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(false));
    assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(true));
    ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "value").startArray("nested1").startObject().field("field1", "1").startArray("nested2").startObject().field("field2", "2").endObject().startObject().field("field2", "3").endObject().endArray().endObject().startObject().field("field1", "4").startArray("nested2").startObject().field("field2", "5").endObject().startObject().field("field2", "6").endObject().endArray().endObject().endArray().endObject().bytes());
    assertThat(doc.docs().size(), equalTo(7));
    assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6"));
    assertThat(doc.docs().get(0).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(0).get("field"), nullValue());
    assertThat(doc.docs().get(1).get("nested1.nested2.field2"), equalTo("5"));
    assertThat(doc.docs().get(1).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(1).get("field"), nullValue());
    assertThat(doc.docs().get(2).get("nested1.field1"), equalTo("4"));
    assertThat(doc.docs().get(2).get("nested1.nested2.field2"), nullValue());
    assertThat(doc.docs().get(2).get("field"), nullValue());
    assertThat(doc.docs().get(3).get("nested1.nested2.field2"), equalTo("3"));
    assertThat(doc.docs().get(3).get("field"), nullValue());
    assertThat(doc.docs().get(4).get("nested1.nested2.field2"), equalTo("2"));
    assertThat(doc.docs().get(4).get("field"), nullValue());
    assertThat(doc.docs().get(5).get("nested1.field1"), equalTo("1"));
    assertThat(doc.docs().get(5).get("nested1.nested2.field2"), nullValue());
    assertThat(doc.docs().get(5).get("field"), nullValue());
    assertThat(doc.docs().get(6).get("field"), equalTo("value"));
    assertThat(doc.docs().get(6).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(6).getFields("nested1.nested2.field2").length, equalTo(4));
}
Also used : CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 88 with CompressedXContent

use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.

the class NestedObjectMapperTests method testMultiNested.

public void testMultiNested() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("nested1").field("type", "nested").startObject("properties").startObject("nested2").field("type", "nested").endObject().endObject().endObject().endObject().endObject().endObject().string();
    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    assertThat(docMapper.hasNestedObjects(), equalTo(true));
    ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
    assertThat(nested1Mapper.nested().isNested(), equalTo(true));
    assertThat(nested1Mapper.nested().isIncludeInParent(), equalTo(false));
    assertThat(nested1Mapper.nested().isIncludeInRoot(), equalTo(false));
    ObjectMapper nested2Mapper = docMapper.objectMappers().get("nested1.nested2");
    assertThat(nested2Mapper.nested().isNested(), equalTo(true));
    assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(false));
    assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false));
    ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "value").startArray("nested1").startObject().field("field1", "1").startArray("nested2").startObject().field("field2", "2").endObject().startObject().field("field2", "3").endObject().endArray().endObject().startObject().field("field1", "4").startArray("nested2").startObject().field("field2", "5").endObject().startObject().field("field2", "6").endObject().endArray().endObject().endArray().endObject().bytes());
    assertThat(doc.docs().size(), equalTo(7));
    assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6"));
    assertThat(doc.docs().get(0).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(0).get("field"), nullValue());
    assertThat(doc.docs().get(1).get("nested1.nested2.field2"), equalTo("5"));
    assertThat(doc.docs().get(1).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(1).get("field"), nullValue());
    assertThat(doc.docs().get(2).get("nested1.field1"), equalTo("4"));
    assertThat(doc.docs().get(2).get("nested1.nested2.field2"), nullValue());
    assertThat(doc.docs().get(2).get("field"), nullValue());
    assertThat(doc.docs().get(3).get("nested1.nested2.field2"), equalTo("3"));
    assertThat(doc.docs().get(3).get("field"), nullValue());
    assertThat(doc.docs().get(4).get("nested1.nested2.field2"), equalTo("2"));
    assertThat(doc.docs().get(4).get("field"), nullValue());
    assertThat(doc.docs().get(5).get("nested1.field1"), equalTo("1"));
    assertThat(doc.docs().get(5).get("nested1.nested2.field2"), nullValue());
    assertThat(doc.docs().get(5).get("field"), nullValue());
    assertThat(doc.docs().get(6).get("field"), equalTo("value"));
    assertThat(doc.docs().get(6).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(6).get("nested1.nested2.field2"), nullValue());
}
Also used : CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 89 with CompressedXContent

use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.

the class NestedObjectMapperTests method testMultiObjectAndNested2.

public void testMultiObjectAndNested2() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("nested1").field("type", "nested").field("include_in_parent", true).startObject("properties").startObject("nested2").field("type", "nested").field("include_in_parent", true).endObject().endObject().endObject().endObject().endObject().endObject().string();
    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    assertThat(docMapper.hasNestedObjects(), equalTo(true));
    ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
    assertThat(nested1Mapper.nested().isNested(), equalTo(true));
    assertThat(nested1Mapper.nested().isIncludeInParent(), equalTo(true));
    assertThat(nested1Mapper.nested().isIncludeInRoot(), equalTo(false));
    ObjectMapper nested2Mapper = docMapper.objectMappers().get("nested1.nested2");
    assertThat(nested2Mapper.nested().isNested(), equalTo(true));
    assertThat(nested2Mapper.nested().isIncludeInParent(), equalTo(true));
    assertThat(nested2Mapper.nested().isIncludeInRoot(), equalTo(false));
    ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "value").startArray("nested1").startObject().field("field1", "1").startArray("nested2").startObject().field("field2", "2").endObject().startObject().field("field2", "3").endObject().endArray().endObject().startObject().field("field1", "4").startArray("nested2").startObject().field("field2", "5").endObject().startObject().field("field2", "6").endObject().endArray().endObject().endArray().endObject().bytes());
    assertThat(doc.docs().size(), equalTo(7));
    assertThat(doc.docs().get(0).get("nested1.nested2.field2"), equalTo("6"));
    assertThat(doc.docs().get(0).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(0).get("field"), nullValue());
    assertThat(doc.docs().get(1).get("nested1.nested2.field2"), equalTo("5"));
    assertThat(doc.docs().get(1).get("nested1.field1"), nullValue());
    assertThat(doc.docs().get(1).get("field"), nullValue());
    assertThat(doc.docs().get(2).get("nested1.field1"), equalTo("4"));
    assertThat(doc.docs().get(2).get("nested1.nested2.field2"), equalTo("5"));
    assertThat(doc.docs().get(2).get("field"), nullValue());
    assertThat(doc.docs().get(3).get("nested1.nested2.field2"), equalTo("3"));
    assertThat(doc.docs().get(3).get("field"), nullValue());
    assertThat(doc.docs().get(4).get("nested1.nested2.field2"), equalTo("2"));
    assertThat(doc.docs().get(4).get("field"), nullValue());
    assertThat(doc.docs().get(5).get("nested1.field1"), equalTo("1"));
    assertThat(doc.docs().get(5).get("nested1.nested2.field2"), equalTo("2"));
    assertThat(doc.docs().get(5).get("field"), nullValue());
    assertThat(doc.docs().get(6).get("field"), equalTo("value"));
    assertThat(doc.docs().get(6).getFields("nested1.field1").length, equalTo(2));
    assertThat(doc.docs().get(6).getFields("nested1.nested2.field2").length, equalTo(4));
}
Also used : CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 90 with CompressedXContent

use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.

the class NestedObjectMapperTests method testSingleNested.

public void testSingleNested() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("nested1").field("type", "nested").endObject().endObject().endObject().endObject().string();
    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    assertThat(docMapper.hasNestedObjects(), equalTo(true));
    ObjectMapper nested1Mapper = docMapper.objectMappers().get("nested1");
    assertThat(nested1Mapper.nested().isNested(), equalTo(true));
    ParsedDocument doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "value").startObject("nested1").field("field1", "1").field("field2", "2").endObject().endObject().bytes());
    assertThat(doc.docs().size(), equalTo(2));
    assertThat(doc.docs().get(0).get(TypeFieldMapper.NAME), equalTo(nested1Mapper.nestedTypePathAsString()));
    assertThat(doc.docs().get(0).get("nested1.field1"), equalTo("1"));
    assertThat(doc.docs().get(0).get("nested1.field2"), equalTo("2"));
    assertThat(doc.docs().get(1).get("field"), equalTo("value"));
    doc = docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "value").startArray("nested1").startObject().field("field1", "1").field("field2", "2").endObject().startObject().field("field1", "3").field("field2", "4").endObject().endArray().endObject().bytes());
    assertThat(doc.docs().size(), equalTo(3));
    assertThat(doc.docs().get(0).get(TypeFieldMapper.NAME), equalTo(nested1Mapper.nestedTypePathAsString()));
    assertThat(doc.docs().get(0).get("nested1.field1"), equalTo("3"));
    assertThat(doc.docs().get(0).get("nested1.field2"), equalTo("4"));
    assertThat(doc.docs().get(1).get(TypeFieldMapper.NAME), equalTo(nested1Mapper.nestedTypePathAsString()));
    assertThat(doc.docs().get(1).get("nested1.field1"), equalTo("1"));
    assertThat(doc.docs().get(1).get("nested1.field2"), equalTo("2"));
    assertThat(doc.docs().get(2).get("field"), equalTo("value"));
}
Also used : CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)366 Matchers.containsString (org.hamcrest.Matchers.containsString)223 IndexableField (org.apache.lucene.index.IndexableField)75 BytesReference (org.elasticsearch.common.bytes.BytesReference)62 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)51 IndexService (org.elasticsearch.index.IndexService)49 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)46 Settings (org.elasticsearch.common.settings.Settings)25 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)19 BytesRef (org.apache.lucene.util.BytesRef)18 BytesArray (org.elasticsearch.common.bytes.BytesArray)16 MapperParsingException (org.elasticsearch.index.mapper.MapperParsingException)16 IOException (java.io.IOException)15 DocumentMapperParser (org.elasticsearch.index.mapper.DocumentMapperParser)15 Map (java.util.Map)13 Document (org.elasticsearch.index.mapper.ParseContext.Document)13 MapperService (org.elasticsearch.index.mapper.MapperService)12 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)10 IndexTemplateMetadata (org.elasticsearch.cluster.metadata.IndexTemplateMetadata)9 FieldMapper (org.elasticsearch.index.mapper.FieldMapper)9