Search in sources :

Example 86 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 87 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 88 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)

Example 89 with DocumentMapper

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

the class SizeMappingTests method testSizeDisabled.

public void testSizeDisabled() throws Exception {
    IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=false");
    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)

Example 90 with DocumentMapper

use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch-opennlp-plugin by spinscale.

the class OpenNlpMappingTest method testAnalyzedOpenNlpFieldMappings.

@Test
public void testAnalyzedOpenNlpFieldMappings() throws IOException {
    String mapping = copyToStringFromClasspath("/test-mapping-keywordanalyzer.json");
    DocumentMapper docMapper = mapperParser.parse(mapping);
    String message = String.format("\"name\":{\"type\":\"string\",\"analyzer\":\"keyword\"}");
    assertThat(docMapper.mappingSource().string(), containsString(message));
}
Also used : DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) Matchers.containsString(org.hamcrest.Matchers.containsString) 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