Search in sources :

Example 81 with DocumentMapper

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

the class MetaDataMappingService method refreshIndexMapping.

private boolean refreshIndexMapping(IndexService indexService, IndexMetaData.Builder builder) {
    boolean dirty = false;
    String index = indexService.index().getName();
    try {
        List<String> updatedTypes = new ArrayList<>();
        for (DocumentMapper mapper : indexService.mapperService().docMappers(true)) {
            final String type = mapper.type();
            if (!mapper.mappingSource().equals(builder.mapping(type).source())) {
                updatedTypes.add(type);
            }
        }
        // if a single type is not up-to-date, re-send everything
        if (updatedTypes.isEmpty() == false) {
            logger.warn("[{}] re-syncing mappings with cluster state because of types [{}]", index, updatedTypes);
            dirty = true;
            for (DocumentMapper mapper : indexService.mapperService().docMappers(true)) {
                builder.putMapping(new MappingMetaData(mapper));
            }
        }
    } catch (Exception e) {
        logger.warn((Supplier<?>) () -> new ParameterizedMessage("[{}] failed to refresh-mapping in cluster state", index), e);
    }
    return dirty;
}
Also used : DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) ArrayList(java.util.ArrayList) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) InvalidTypeNameException(org.elasticsearch.indices.InvalidTypeNameException) IOException(java.io.IOException)

Example 82 with DocumentMapper

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

the class ChildrenAggregationBuilder method resolveConfig.

@Override
protected ValuesSourceConfig<ParentChild> resolveConfig(SearchContext context) {
    ValuesSourceConfig<ParentChild> config = new ValuesSourceConfig<>(ValuesSourceType.BYTES);
    DocumentMapper childDocMapper = context.mapperService().documentMapper(childType);
    if (childDocMapper != null) {
        ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper();
        if (!parentFieldMapper.active()) {
            throw new IllegalArgumentException("[children] no [_parent] field not configured that points to a parent type");
        }
        parentType = parentFieldMapper.type();
        DocumentMapper parentDocMapper = context.mapperService().documentMapper(parentType);
        if (parentDocMapper != null) {
            parentFilter = parentDocMapper.typeFilter();
            childFilter = childDocMapper.typeFilter();
            ParentChildIndexFieldData parentChildIndexFieldData = context.fieldData().getForField(parentFieldMapper.fieldType());
            config.fieldContext(new FieldContext(parentFieldMapper.fieldType().name(), parentChildIndexFieldData, parentFieldMapper.fieldType()));
        } else {
            config.unmapped(true);
        }
    } else {
        config.unmapped(true);
    }
    return config;
}
Also used : ParentFieldMapper(org.elasticsearch.index.mapper.ParentFieldMapper) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) ValuesSourceConfig(org.elasticsearch.search.aggregations.support.ValuesSourceConfig) FieldContext(org.elasticsearch.search.aggregations.support.FieldContext) ParentChildIndexFieldData(org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData) ParentChild(org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.ParentChild)

Example 83 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)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