Search in sources :

Example 31 with PutMappingResponse

use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project ecs-dashboard by carone1.

the class ElasticS3ObjectDAO method initS3ObjectIndex.

// =======================
// Private methods
// =======================
/**
 * Init Object index
 */
private void initS3ObjectIndex(Date collectionTime) {
    String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
    s3ObjectIndexDayName = S3_OBJECT_INDEX_NAME + "-" + collectionDayString;
    if (elasticClient.admin().indices().exists(new IndicesExistsRequest(s3ObjectIndexDayName)).actionGet().isExists()) {
        // Index already exists need to truncate it and recreate it
        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(s3ObjectIndexDayName);
        ActionFuture<DeleteIndexResponse> futureResult = elasticClient.admin().indices().delete(deleteIndexRequest);
        // Wait until deletion is done
        while (!futureResult.isDone()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    elasticClient.admin().indices().create(new CreateIndexRequest(s3ObjectIndexDayName)).actionGet();
    try {
        PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(s3ObjectIndexDayName).setType(S3_OBJECT_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(S3_OBJECT_INDEX_TYPE).startObject("properties").startObject(LAST_MODIFIED_TAG).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().startObject(SIZE_TAG).field("type", "string").field("type", "long").endObject().startObject(KEY_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(KEY_TAG + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(ETAG_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NAMESPACE_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(BUCKET_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_ID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_NAME_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(COLLECTION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().startObject(CUSTOM_GID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(CUSTOM_UID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(CUSTOM_MODIFIED_TIME_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().endObject().startArray("dynamic_templates").startObject().startObject("notanalyzed").field("match", "*").field("match_mapping_type", "string").startObject("mapping").field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().endObject().endObject().endArray().endObject().endObject()).execute().actionGet();
        if (putMappingResponse.isAcknowledged()) {
            LOGGER.info("Index Created: " + s3ObjectIndexDayName);
        } else {
            LOGGER.error("Index {} did not exist. " + "While attempting to create the index from stored ElasticSearch " + "Templates we were unable to get an acknowledgement.", s3ObjectIndexDayName);
            LOGGER.error("Error Message: {}", putMappingResponse.toString());
            throw new RuntimeException("Unable to create index " + s3ObjectIndexDayName);
        }
    } catch (IOException e) {
        throw new RuntimeException("Unable to create index " + s3ObjectIndexDayName + " " + e.getMessage());
    }
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) IOException(java.io.IOException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Example 32 with PutMappingResponse

use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project ecs-dashboard by carone1.

the class ElasticS3ObjectDAO method initS3ObjectVersionIndex.

/**
 * Init Object version index
 */
private void initS3ObjectVersionIndex(Date collectionTime) {
    String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
    s3ObjectVersionIndexDayName = S3_OBJECT_VERSION_INDEX_NAME + "-" + collectionDayString;
    if (elasticClient.admin().indices().exists(new IndicesExistsRequest(s3ObjectVersionIndexDayName)).actionGet().isExists()) {
        // Index already exists need to truncate it and recreate it
        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(s3ObjectVersionIndexDayName);
        ActionFuture<DeleteIndexResponse> futureResult = elasticClient.admin().indices().delete(deleteIndexRequest);
        // Wait until deletion is done
        while (!futureResult.isDone()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    elasticClient.admin().indices().create(new CreateIndexRequest(s3ObjectVersionIndexDayName)).actionGet();
    try {
        PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(s3ObjectVersionIndexDayName).setType(S3_OBJECT_VERSION_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(S3_OBJECT_VERSION_INDEX_TYPE).startObject("properties").startObject(LAST_MODIFIED_TAG).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().startObject(SIZE_TAG).field("type", "string").field("type", "long").endObject().startObject(KEY_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(KEY_TAG + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(ETAG_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NAMESPACE_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(BUCKET_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VERSION_ID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(IS_LATEST_TAG).field("type", "boolean").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_ID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_NAME_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(COLLECTION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().endObject().startArray("dynamic_templates").startObject().startObject("notanalyzed").field("match", "*").field("match_mapping_type", "string").startObject("mapping").field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().endObject().endObject().endArray().endObject().endObject()).execute().actionGet();
        if (putMappingResponse.isAcknowledged()) {
            LOGGER.info("Index Created: " + s3ObjectVersionIndexDayName);
        } else {
            LOGGER.error("Index {} did not exist. " + "While attempting to create the index from stored ElasticSearch " + "Templates we were unable to get an acknowledgement.", s3ObjectVersionIndexDayName);
            LOGGER.error("Error Message: {}", putMappingResponse.toString());
            throw new RuntimeException("Unable to create index " + s3ObjectVersionIndexDayName);
        }
    } catch (IOException e) {
        throw new RuntimeException("Unable to create index " + s3ObjectVersionIndexDayName + " " + e.getMessage());
    }
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) IOException(java.io.IOException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Example 33 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 34 with PutMappingResponse

use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project uavstack by uavorg.

the class ESClient method setIndexTypeMapping.

/**
 * setIndexTypeMapping require Index Creation first
 *
 * @param index
 * @param type
 * @param properties
 * @return
 * @throws IOException
 */
public boolean setIndexTypeMapping(String index, String type, Map<String, Map<String, Object>> properties) throws IOException {
    PutMappingRequest pmp = Requests.putMappingRequest(index).type(type).source(createMapping(type, properties));
    PutMappingResponse resp = client.admin().indices().putMapping(pmp).actionGet();
    return resp.isAcknowledged();
}
Also used : PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)

Example 35 with PutMappingResponse

use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project vertigo by KleeGroup.

the class AbstractESSearchServicesPlugin method updateTypeMapping.

/**
 * Update template definition of this type.
 * @param indexDefinition Index concerné
 */
private void updateTypeMapping(final SearchIndexDefinition indexDefinition, final boolean sortableNormalizer) {
    Assertion.checkNotNull(indexDefinition);
    // -----
    try (final XContentBuilder typeMapping = XContentFactory.jsonBuilder()) {
        typeMapping.startObject().startObject("properties").startObject(ESDocumentCodec.FULL_RESULT).field("type", "binary").endObject();
        /* 3 : Les champs du dto index */
        final Set<DtField> copyFromFields = indexDefinition.getIndexCopyFromFields();
        final DtDefinition indexDtDefinition = indexDefinition.getIndexDtDefinition();
        for (final DtField dtField : indexDtDefinition.getFields()) {
            final IndexType indexType = IndexType.readIndexType(dtField.getDomain());
            typeMapping.startObject(dtField.getName());
            appendIndexTypeMapping(typeMapping, indexType);
            if (copyFromFields.contains(dtField)) {
                appendIndexCopyToMapping(indexDefinition, typeMapping, dtField);
            }
            if (indexType.isIndexSubKeyword()) {
                typeMapping.startObject("fields");
                typeMapping.startObject("keyword");
                typeMapping.field("type", "keyword");
                if (sortableNormalizer) {
                    typeMapping.field("normalizer", "sortable");
                }
                typeMapping.endObject();
                typeMapping.endObject();
            }
            if (indexType.isIndexFieldData()) {
                typeMapping.field("fielddata", true);
            }
            typeMapping.endObject();
        }
        // end properties
        typeMapping.endObject().endObject();
        final PutMappingResponse putMappingResponse = esClient.admin().indices().preparePutMapping(obtainIndexName(indexDefinition)).setType(indexDefinition.getName().toLowerCase(Locale.ROOT)).setSource(typeMapping).get();
        putMappingResponse.isAcknowledged();
    } catch (final IOException e) {
        throw WrappedException.wrap(e, "Serveur ElasticSearch indisponible");
    }
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Aggregations

PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)37 IOException (java.io.IOException)19 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)11 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)9 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)9 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)9 GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)7 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)7 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)4 ClusterState (org.elasticsearch.cluster.ClusterState)4 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 PutMappingRequest (org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest)3 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)3 TitanException (com.thinkaurelius.titan.core.TitanException)2 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)2 DtField (io.vertigo.dynamo.domain.metamodel.DtField)2 Map (java.util.Map)2