Search in sources :

Example 61 with DocumentMapper

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

the class DocumentMapperMergeTests method testMergeObjectAndNested.

public void testMergeObjectAndNested() throws Exception {
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
    String objectMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("obj").field("type", "object").endObject().endObject().endObject().endObject().string();
    DocumentMapper objectMapper = parser.parse("type1", new CompressedXContent(objectMapping));
    String nestedMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("obj").field("type", "nested").endObject().endObject().endObject().endObject().string();
    DocumentMapper nestedMapper = parser.parse("type1", new CompressedXContent(nestedMapping));
    try {
        objectMapper.merge(nestedMapper.mapping(), false);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("object mapping [obj] can't be changed from non-nested to nested"));
    }
    try {
        nestedMapper.merge(objectMapper.mapping(), false);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("object mapping [obj] can't be changed from nested to non-nested"));
    }
}
Also used : DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 62 with DocumentMapper

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

the class DocumentMapperMergeTests method testChangeSearchAnalyzerToDefault.

public void testChangeSearchAnalyzerToDefault() throws Exception {
    MapperService mapperService = createIndex("test").mapperService();
    String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "text").field("analyzer", "standard").field("search_analyzer", "whitespace").endObject().endObject().endObject().endObject().string();
    String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "text").field("analyzer", "standard").endObject().endObject().endObject().endObject().string();
    DocumentMapper existing = mapperService.merge("type", new CompressedXContent(mapping1), MapperService.MergeReason.MAPPING_UPDATE, false);
    DocumentMapper merged = mapperService.merge("type", new CompressedXContent(mapping2), MapperService.MergeReason.MAPPING_UPDATE, false);
    assertThat(((NamedAnalyzer) existing.mappers().getMapper("field").fieldType().searchAnalyzer()).name(), equalTo("whitespace"));
    assertThat(((NamedAnalyzer) merged.mappers().getMapper("field").fieldType().searchAnalyzer()).name(), equalTo("standard"));
}
Also used : DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString) MapperService(org.elasticsearch.index.mapper.MapperService)

Example 63 with DocumentMapper

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

the class DocumentMapperParserTests method testFieldNameWithDeepDots.

public void testFieldNameWithDeepDots() throws Exception {
    IndexService indexService = createIndex("test");
    DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo.bar").field("type", "text").endObject().startObject("foo.baz").startObject("properties").startObject("deep.field").field("type", "keyword").endObject().endObject().endObject().endObject().endObject().endObject().string();
    DocumentMapper docMapper = mapperParser.parse("type", new CompressedXContent(mapping));
    assertNotNull(docMapper.mappers().getMapper("foo.bar"));
    assertNotNull(docMapper.mappers().getMapper("foo.baz.deep.field"));
    assertNotNull(docMapper.objectMappers().get("foo"));
}
Also used : IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 64 with DocumentMapper

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

the class Murmur3FieldMapperTests method testDefaults.

public void testDefaults() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "murmur3").endObject().endObject().endObject().endObject().string();
    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
    ParsedDocument parsedDoc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "value").endObject().bytes());
    IndexableField[] fields = parsedDoc.rootDoc().getFields("field");
    assertNotNull(fields);
    assertEquals(Arrays.toString(fields), 1, fields.length);
    IndexableField field = fields[0];
    assertEquals(IndexOptions.NONE, field.fieldType().indexOptions());
    assertEquals(DocValuesType.SORTED_NUMERIC, field.fieldType().docValuesType());
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 65 with DocumentMapper

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

the class SizeMappingTests method testSizeNotSet.

public void testSizeNotSet() throws Exception {
    IndexService service = createIndex("test", Settings.EMPTY, "type");
    DocumentMapper docMapper = service.mapperService().documentMapper("type");
    BytesReference source = XContentFactory.jsonBuilder().startObject().field("field", "value").endObject().bytes();
    ParsedDocument doc = docMapper.parse(SourceToParse.source("test", "type", "1", source, XContentType.JSON));
    assertThat(doc.rootDoc().getField("_size"), nullValue());
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper)

Aggregations

DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)83 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)49 IndexService (org.elasticsearch.index.IndexService)29 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)27 IndexableField (org.apache.lucene.index.IndexableField)19 FieldMapper (org.elasticsearch.index.mapper.FieldMapper)15 Matchers.containsString (org.hamcrest.Matchers.containsString)15 Settings (org.elasticsearch.common.settings.Settings)13 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)12 MapperService (org.elasticsearch.index.mapper.MapperService)12 BytesReference (org.elasticsearch.common.bytes.BytesReference)11 DocumentMapperParser (org.elasticsearch.index.mapper.DocumentMapperParser)10 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)9 BytesArray (org.elasticsearch.common.bytes.BytesArray)8 Document (org.elasticsearch.index.mapper.ParseContext.Document)8 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 BytesRef (org.apache.lucene.util.BytesRef)6 ParentFieldMapper (org.elasticsearch.index.mapper.ParentFieldMapper)6