Search in sources :

Example 21 with PutMappingResponse

use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project play2-elasticsearch by cleverage.

the class IndexService method createMapping.

/**
     * Create Mapping ( for example mapping type : nested, geo_point  )
     * see http://www.elasticsearch.org/guide/reference/mapping/
     * <p/>
     * {
     * "tweet" : {
     * "properties" : {
     * "message" : {"type" : "string", "store" : "yes"}
     * }
     * }
     * }
     *
     * @param indexName
     * @param indexType
     * @param indexMapping
     */
public static PutMappingResponse createMapping(String indexName, String indexType, String indexMapping) {
    Logger.debug("ElasticSearch : creating mapping [" + indexName + "/" + indexType + "] :  " + indexMapping);
    PutMappingResponse response = IndexClient.client.admin().indices().preparePutMapping(indexName).setType(indexType).setSource(indexMapping).execute().actionGet();
    return response;
}
Also used : PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)

Example 22 with PutMappingResponse

use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse 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

PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)22 IOException (java.io.IOException)7 GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)6 ClusterState (org.elasticsearch.cluster.ClusterState)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)3 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)3 Map (java.util.Map)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)2 IndexResponse (org.elasticsearch.action.index.IndexResponse)2 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)2 Settings (org.elasticsearch.common.settings.Settings)2 Index (org.elasticsearch.index.Index)2 IndexService (org.elasticsearch.index.IndexService)2 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)2 MapperService (org.elasticsearch.index.mapper.MapperService)2 IndicesService (org.elasticsearch.indices.IndicesService)2