Search in sources :

Example 26 with GetMappingsResponse

use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project fess by codelibs.

the class FessEsClient method addMapping.

public void addMapping(final String index, final String docType, final String indexName) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings(indexName).execute().actionGet(fessConfig.getIndexIndicesTimeout());
    final ImmutableOpenMap<String, MappingMetaData> indexMappings = getMappingsResponse.mappings().get(indexName);
    if (indexMappings == null || !indexMappings.containsKey(docType)) {
        String source = null;
        final String mappingFile = indexConfigPath + "/" + index + "/" + docType + ".json";
        try {
            source = FileUtil.readUTF8(mappingFile);
        } catch (final Exception e) {
            logger.warn(mappingFile + " is not found.", e);
        }
        try {
            final PutMappingResponse putMappingResponse = client.admin().indices().preparePutMapping(indexName).setType(docType).setSource(source, XContentFactory.xContentType(source)).execute().actionGet(fessConfig.getIndexIndicesTimeout());
            if (putMappingResponse.isAcknowledged()) {
                logger.info("Created " + indexName + "/" + docType + " mapping.");
            } else {
                logger.warn("Failed to create " + indexName + "/" + docType + " mapping.");
            }
            final String dataPath = indexConfigPath + "/" + index + "/" + docType + ".bulk";
            if (ResourceUtil.isExist(dataPath)) {
                insertBulkData(fessConfig, index, docType, dataPath);
            }
        } catch (final Exception e) {
            logger.warn("Failed to create " + indexName + "/" + docType + " mapping.", e);
        }
    } else if (logger.isDebugEnabled()) {
        logger.debug(indexName + "/" + docType + " mapping exists.");
    }
}
Also used : PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException) FessSystemException(org.codelibs.fess.exception.FessSystemException) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ElasticsearchException(org.elasticsearch.ElasticsearchException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) SearchQueryException(org.codelibs.fess.exception.SearchQueryException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)

Aggregations

GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)26 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)11 Map (java.util.Map)8 PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 IOException (java.io.IOException)4 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Client (org.elasticsearch.client.Client)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 TypeMissingException (org.elasticsearch.indices.TypeMissingException)2 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)1 ReadContext (com.jayway.jsonpath.ReadContext)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1