Search in sources :

Example 56 with DocumentMapper

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

the class PercolatorFieldMapperTests method testExtractTermsAndRanges_failed.

public void testExtractTermsAndRanges_failed() throws Exception {
    addQueryMapping();
    TermRangeQuery query = new TermRangeQuery("field1", new BytesRef("a"), new BytesRef("z"), true, true);
    DocumentMapper documentMapper = mapperService.documentMapper(typeName);
    PercolatorFieldMapper fieldMapper = (PercolatorFieldMapper) documentMapper.mappers().getMapper(fieldName);
    ParseContext.InternalParseContext parseContext = new ParseContext.InternalParseContext(Settings.EMPTY, mapperService.documentMapperParser(), documentMapper, null, null);
    fieldMapper.processQuery(query, parseContext);
    ParseContext.Document document = parseContext.doc();
    PercolatorFieldMapper.FieldType fieldType = (PercolatorFieldMapper.FieldType) fieldMapper.fieldType();
    assertThat(document.getFields().size(), equalTo(1));
    assertThat(document.getField(fieldType.extractionResultField.name()).stringValue(), equalTo(EXTRACTION_FAILED));
}
Also used : TermRangeQuery(org.apache.lucene.search.TermRangeQuery) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) ParseContext(org.elasticsearch.index.mapper.ParseContext) QueryParseContext(org.elasticsearch.index.query.QueryParseContext) BytesRef(org.apache.lucene.util.BytesRef)

Example 57 with DocumentMapper

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

the class PercolatorFieldMapperTests method testExtractTermsAndRanges_partial.

public void testExtractTermsAndRanges_partial() throws Exception {
    addQueryMapping();
    PhraseQuery phraseQuery = new PhraseQuery("field", "term");
    DocumentMapper documentMapper = mapperService.documentMapper(typeName);
    PercolatorFieldMapper fieldMapper = (PercolatorFieldMapper) documentMapper.mappers().getMapper(fieldName);
    ParseContext.InternalParseContext parseContext = new ParseContext.InternalParseContext(Settings.EMPTY, mapperService.documentMapperParser(), documentMapper, null, null);
    fieldMapper.processQuery(phraseQuery, parseContext);
    ParseContext.Document document = parseContext.doc();
    PercolatorFieldMapper.FieldType fieldType = (PercolatorFieldMapper.FieldType) fieldMapper.fieldType();
    assertThat(document.getFields().size(), equalTo(2));
    assertThat(document.getFields().get(0).binaryValue().utf8ToString(), equalTo("fieldterm"));
    assertThat(document.getField(fieldType.extractionResultField.name()).stringValue(), equalTo(EXTRACTION_PARTIAL));
}
Also used : PhraseQuery(org.apache.lucene.search.PhraseQuery) QueryBuilders.matchPhraseQuery(org.elasticsearch.index.query.QueryBuilders.matchPhraseQuery) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) ParseContext(org.elasticsearch.index.mapper.ParseContext) QueryParseContext(org.elasticsearch.index.query.QueryParseContext)

Example 58 with DocumentMapper

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

the class ESIntegTestCase method assertConcreteMappingsOnAll.

/**
     * Waits till a (pattern) field name mappings concretely exists on all nodes. Note, this waits for the current
     * started shards and checks for concrete mappings.
     */
public void assertConcreteMappingsOnAll(final String index, final String type, final String... fieldNames) throws Exception {
    Set<String> nodes = internalCluster().nodesInclude(index);
    assertThat(nodes, Matchers.not(Matchers.emptyIterable()));
    for (String node : nodes) {
        IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node);
        IndexService indexService = indicesService.indexService(resolveIndex(index));
        assertThat("index service doesn't exists on " + node, indexService, notNullValue());
        DocumentMapper documentMapper = indexService.mapperService().documentMapper(type);
        assertThat("document mapper doesn't exists on " + node, documentMapper, notNullValue());
        for (String fieldName : fieldNames) {
            Collection<String> matches = documentMapper.mappers().simpleMatchToFullName(fieldName);
            assertThat("field " + fieldName + " doesn't exists on " + node, matches, Matchers.not(emptyIterable()));
        }
    }
    assertMappingOnMaster(index, type, fieldNames);
}
Also used : IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) IndicesService(org.elasticsearch.indices.IndicesService)

Example 59 with DocumentMapper

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

the class MetaDataMappingServiceTests method testAddExtraChildTypePointingToAlreadyParentExistingType.

// Tests _parent meta field logic, because part of the validation is in MetaDataMappingService
public void testAddExtraChildTypePointingToAlreadyParentExistingType() throws Exception {
    IndexService indexService = createIndex("test", client().admin().indices().prepareCreate("test").addMapping("parent").addMapping("child1", "_parent", "type=parent"));
    // adding the extra child type that points to an already existing parent type is allowed:
    client().admin().indices().preparePutMapping("test").setType("child2").setSource("_parent", "type=parent").get();
    DocumentMapper documentMapper = indexService.mapperService().documentMapper("child2");
    assertThat(documentMapper.parentFieldMapper().type(), equalTo("parent"));
    assertThat(documentMapper.parentFieldMapper().active(), is(true));
}
Also used : IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper)

Example 60 with DocumentMapper

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

the class DynamicTemplatesTests method testSimpleWithXContentTraverse.

public void testSimpleWithXContentTraverse() throws Exception {
    String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-mapping.json");
    IndexService index = createIndex("test");
    client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get();
    DocumentMapper docMapper = index.mapperService().documentMapper("person");
    byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json");
    ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", new BytesArray(json));
    client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
    docMapper = index.mapperService().documentMapper("person");
    Document doc = parsedDoc.rootDoc();
    IndexableField f = doc.getField("name");
    assertThat(f.name(), equalTo("name"));
    assertThat(f.binaryValue(), equalTo(new BytesRef("some name")));
    assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
    assertThat(f.fieldType().tokenized(), equalTo(false));
    FieldMapper fieldMapper = docMapper.mappers().getMapper("name");
    assertNotNull(fieldMapper);
    f = doc.getField("multi1");
    assertThat(f.name(), equalTo("multi1"));
    assertThat(f.stringValue(), equalTo("multi 1"));
    assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
    assertThat(f.fieldType().tokenized(), equalTo(true));
    fieldMapper = docMapper.mappers().getMapper("multi1");
    assertNotNull(fieldMapper);
    f = doc.getField("multi1.org");
    assertThat(f.name(), equalTo("multi1.org"));
    assertThat(f.binaryValue(), equalTo(new BytesRef("multi 1")));
    assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
    assertThat(f.fieldType().tokenized(), equalTo(false));
    fieldMapper = docMapper.mappers().getMapper("multi1.org");
    assertNotNull(fieldMapper);
    f = doc.getField("multi2");
    assertThat(f.name(), equalTo("multi2"));
    assertThat(f.stringValue(), equalTo("multi 2"));
    assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
    assertThat(f.fieldType().tokenized(), equalTo(true));
    fieldMapper = docMapper.mappers().getMapper("multi2");
    assertNotNull(fieldMapper);
    f = doc.getField("multi2.org");
    assertThat(f.name(), equalTo("multi2.org"));
    assertThat(f.binaryValue(), equalTo(new BytesRef("multi 2")));
    assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
    assertThat(f.fieldType().tokenized(), equalTo(false));
    fieldMapper = docMapper.mappers().getMapper("multi2.org");
    assertNotNull(fieldMapper);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) BytesArray(org.elasticsearch.common.bytes.BytesArray) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) Document(org.elasticsearch.index.mapper.ParseContext.Document) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) FieldMapper(org.elasticsearch.index.mapper.FieldMapper) BytesRef(org.apache.lucene.util.BytesRef)

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