Search in sources :

Example 96 with DocumentMapper

use of org.elasticsearch.index.mapper.DocumentMapper in project crate by crate.

the class ArrayMapperTest method testParseDynamicNullArray.

@Test
public void testParseDynamicNullArray() throws Exception {
    String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject(TYPE).startObject("properties").endObject().endObject().endObject());
    DocumentMapper mapper = mapper(INDEX, mapping);
    // parse source with null array
    BytesReference bytesReference = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startArray("new_array_field").nullValue().endArray().endObject());
    SourceToParse sourceToParse = new SourceToParse(INDEX, "abc", bytesReference, XContentType.JSON);
    ParsedDocument doc = mapper.parse(sourceToParse);
    assertThat(doc.docs().get(0).getField("new_array_field"), is(nullValue()));
    assertThat(mapper.mappers().getMapper("new_array_field"), is(nullValue()));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) SourceToParse(org.elasticsearch.index.mapper.SourceToParse) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)96 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)51 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)35 IndexService (org.elasticsearch.index.IndexService)30 IndexableField (org.apache.lucene.index.IndexableField)20 BytesReference (org.elasticsearch.common.bytes.BytesReference)20 FieldMapper (org.elasticsearch.index.mapper.FieldMapper)16 Matchers.containsString (org.hamcrest.Matchers.containsString)15 Settings (org.elasticsearch.common.settings.Settings)14 MapperService (org.elasticsearch.index.mapper.MapperService)14 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)12 DocumentMapperParser (org.elasticsearch.index.mapper.DocumentMapperParser)11 Test (org.junit.Test)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)10 Document (org.elasticsearch.index.mapper.ParseContext.Document)10 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)9 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)8 BytesArray (org.elasticsearch.common.bytes.BytesArray)8 Map (java.util.Map)7