Search in sources :

Example 61 with CompressedXContent

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

the class DateFieldMapperTests method testNoDocValues.

public void testNoDocValues() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "date").field("doc_values", false).endObject().endObject().endObject().endObject().string();
    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
    assertEquals(mapping, mapper.mappingSource().toString());
    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "2016-03-11").endObject().bytes());
    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(1, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 62 with CompressedXContent

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

the class DateFieldMapperTests method testDefaults.

public void testDefaults() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "date").endObject().endObject().endObject().endObject().string();
    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
    assertEquals(mapping, mapper.mappingSource().toString());
    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "2016-03-11").endObject().bytes());
    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    assertEquals(8, pointField.fieldType().pointNumBytes());
    assertFalse(pointField.fieldType().stored());
    assertEquals(1457654400000L, pointField.numericValue().longValue());
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
    assertEquals(1457654400000L, dvField.numericValue().longValue());
    assertFalse(dvField.fieldType().stored());
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 63 with CompressedXContent

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

the class DateFieldMapperTests method testNullValue.

public void testNullValue() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "date").endObject().endObject().endObject().endObject().string();
    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
    assertEquals(mapping, mapper.mappingSource().toString());
    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().nullField("field").endObject().bytes());
    assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field"));
    mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "date").field("null_value", "2016-03-11").endObject().endObject().endObject().endObject().string();
    mapper = parser.parse("type", new CompressedXContent(mapping));
    assertEquals(mapping, mapper.mappingSource().toString());
    doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().nullField("field").endObject().bytes());
    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);
    IndexableField pointField = fields[0];
    assertEquals(1, pointField.fieldType().pointDimensionCount());
    assertEquals(8, pointField.fieldType().pointNumBytes());
    assertFalse(pointField.fieldType().stored());
    assertEquals(1457654400000L, pointField.numericValue().longValue());
    IndexableField dvField = fields[1];
    assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType());
    assertEquals(1457654400000L, dvField.numericValue().longValue());
    assertFalse(dvField.fieldType().stored());
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 64 with CompressedXContent

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

the class DocumentParserTests method testDynamicDottedFieldNameLongWithExistingParent.

public void testDynamicDottedFieldNameLongWithExistingParent() throws Exception {
    DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo").field("type", "object").endObject().endObject().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));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 65 with CompressedXContent

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

the class DocumentParserTests method testSimpleParser.

public void testSimpleParser() throws Exception {
    String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/simple/test-mapping.json");
    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping));
    assertThat((String) docMapper.meta().get("param1"), equalTo("value1"));
    BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json"));
    Document doc = docMapper.parse("test", "person", "1", json).rootDoc();
    assertThat(doc.get(docMapper.uidMapper().fieldType().name()), equalTo(Uid.createUid("person", "1")));
    assertThat(doc.get(docMapper.mappers().getMapper("name.first").fieldType().name()), equalTo("shay"));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) BytesArray(org.elasticsearch.common.bytes.BytesArray) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString) Document(org.elasticsearch.index.mapper.ParseContext.Document)

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