Search in sources :

Example 86 with BytesReference

use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.

the class DocumentParserTests method testDynamicFalseLongArray.

public void testDynamicFalseLongArray() 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().startArray("foo").value(0).value(1).endArray().endObject().bytes();
    ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
    assertEquals(0, doc.rootDoc().getFields("foo").length);
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 87 with BytesReference

use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.

the class DocumentParserTests method testFieldDisabled.

public void testFieldDisabled() throws Exception {
    DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo").field("enabled", false).endObject().startObject("bar").field("type", "integer").endObject().endObject().endObject().endObject().string();
    DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
    BytesReference bytes = XContentFactory.jsonBuilder().startObject().field("foo", "1234").field("bar", 10).endObject().bytes();
    ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
    assertNull(doc.rootDoc().getField("foo"));
    assertNotNull(doc.rootDoc().getField("bar"));
    assertNotNull(doc.rootDoc().getField(UidFieldMapper.NAME));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 88 with BytesReference

use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.

the class DocumentParserTests method testDynamicDottedFieldNameObject.

public void testDynamicDottedFieldNameObject() 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().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));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 89 with BytesReference

use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.

the class DocumentParserTests method testDynamicDateDetectionEnabledWithNoSpecialCharacters.

public void testDynamicDateDetectionEnabledWithNoSpecialCharacters() throws IOException {
    DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startArray("dynamic_date_formats").value("yyyy MM").endArray().endObject().endObject().string();
    DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping));
    BytesReference bytes = XContentFactory.jsonBuilder().startObject().field("foo", "2016 12").endObject().bytes();
    // We should have generated a date field
    ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
    Mapping update = doc.dynamicMappingsUpdate();
    assertNotNull(update);
    Mapper dateMapper = update.root().getMapper("foo");
    assertNotNull(dateMapper);
    assertThat(dateMapper, instanceOf(DateFieldMapper.class));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 90 with BytesReference

use of org.elasticsearch.common.bytes.BytesReference in project elasticsearch by elastic.

the class DocumentParserTests method testDynamicGeoPointArrayWithTemplate.

public void testDynamicGeoPointArrayWithTemplate() 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", "geo_point").field("doc_values", false).endObject().endObject().endObject().endArray().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);
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

BytesReference (org.elasticsearch.common.bytes.BytesReference)318 Matchers.containsString (org.hamcrest.Matchers.containsString)72 XContentParser (org.elasticsearch.common.xcontent.XContentParser)63 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)61 IOException (java.io.IOException)58 XContentType (org.elasticsearch.common.xcontent.XContentType)50 BytesArray (org.elasticsearch.common.bytes.BytesArray)47 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)37 ArrayList (java.util.ArrayList)30 HashMap (java.util.HashMap)30 Map (java.util.Map)26 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)26 Test (org.junit.Test)25 List (java.util.List)24 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)24 Version (org.elasticsearch.Version)22 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)20 ReleasableBytesReference (org.elasticsearch.common.bytes.ReleasableBytesReference)19 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)18 BytesRef (org.apache.lucene.util.BytesRef)18