/** * Setup ElasticSearch type mappings as a template that applies to all new indexes. * Applies to all indexes that* start with our prefix. */ private void createMappings(final String indexName) { //Added For Graphite Metrics PutMappingResponse pitr = provider.getClient().admin().indices().preparePutMapping( indexName ).setType( "entity" ).setSource( getMappingsContent() ).execute().actionGet(); if ( !pitr.isAcknowledged() ) { throw new RuntimeException( "Unable to create default mappings" ); } }
/** * Setup ElasticSearch type mappings as a template that applies to all new indexes. * Applies to all indexes that* start with our prefix. */ private void createMappings(final String indexName) throws IOException { //Added For Graphite Metrics Timer.Context timePutIndex = mappingTimer.time(); PutMappingResponse pitr = esProvider.getClient().admin().indices().preparePutMapping( indexName ).setType( "entity" ).setSource( getMappingsContent() ).execute().actionGet(); timePutIndex.stop(); if ( !pitr.isAcknowledged() ) { throw new IndexException( "Unable to create default mappings" ); } }
.setSource(entry.getValue().getAttributes()) .get(); if (!mappingResponse.isAcknowledged()) { throw new IllegalStateException("Failed to create type " + entry.getKey());
PutMappingResponse pmr = client.admin().indices().preparePutMapping(index).setType(type) .setSource(mapping.getSourceAsMap()).get(); if (!pmr.isAcknowledged()) { logger.error("Failed to put mapping {} / {} / {}.", index, type, mapping.source()); } else {
.setSource(entry.getValue().getAttributes()) .get(); if (!mappingResponse.isAcknowledged()) { throw new IllegalStateException("Failed to create type " + entry.getKey());
@Override public void onResponse(PutMappingResponse putMappingResponse) { JsonObject json = new JsonObject() .put("acknowledged", putMappingResponse.isAcknowledged()); resultHandler.handle(Future.succeededFuture(json)); }
@Override protected XContentBuilder toXContent(PutMappingRequest request, PutMappingResponse response, XContentBuilder builder) throws IOException { builder.startObject() .field(Fields.OK, true) .field(Fields.ACKNOWLEDGED, response.isAcknowledged()); builder.endObject(); return builder; } }
/** * Update mappings synchronously on the master node, waiting for at most * {@code timeout}. When this method returns successfully mappings have * been applied to the master node and propagated to data nodes. */ public void updateMappingOnMaster(Index index, String type, Mapping mappingUpdate, TimeValue timeout) throws Exception { if (updateMappingRequest(index, type, mappingUpdate, timeout).get().isAcknowledged() == false) { throw new TimeoutException("Failed to acknowledge mapping update within [" + timeout + "]"); } } }
/** * Update mappings synchronously on the master node, waiting for at most * {@code timeout}. When this method returns successfully mappings have * been applied to the master node and propagated to data nodes. */ public void updateMappingOnMasterSynchronously(String index, String type, Mapping mappingUpdate, TimeValue timeout) throws Throwable { if (updateMappingRequest(index, type, mappingUpdate, timeout).get().isAcknowledged() == false) { throw new TimeoutException("Failed to acknowledge mapping update within [" + timeout + "]"); } }
@Override public void onResponse(PutMappingResponse response) { if (response.isAcknowledged()) { listener.onMappingUpdate(); } else { listener.onFailure(new TimeoutException("Failed to acknowledge the mapping response within [" + timeout + "]")); } }
PutMappingRequestBuilder pmrb = this.client.admin().indices().preparePutMapping(INDEX_NAME) .setType("backup"); pmrb.setSource(this.getIndexCustomFieldMapping()); PutMappingResponse putMappingResponse = pmrb.execute().actionGet(); if (!putMappingResponse.isAcknowledged()) { this.logger.error("Could not create index [" + INDEX_NAME + " ]."); } else { this.logger.debug("Successfully created index [" + INDEX_NAME + " ]."); }
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { LOG.debug("Creating the {} mapping type for the index {}", mappingType, indexName); String source = IOUtils.toString(indexMapping.getInputStream(), "UTF-8"); PutMappingRequestBuilder request = esClient.admin().indices().preparePutMapping(indexName); request.setSource(source, contentType).setType(mappingType); PutMappingResponse response = request.execute().actionGet(); if (!response.isAcknowledged()) { throw new RuntimeException("The index mappings has not been acknowledged"); } ElasticSearchHelper.refreshIndex(esClient, indexName); LOG.info("{} mapping type created for the index {}", StringUtils.capitalize(mappingType), indexName); return RepeatStatus.FINISHED; }
/** * Put index mapping * * @param context * @param nodeName * @param indexName * @param type * @param mappingBuilder * @throws ElasticsearchException * @throws Exception */ private void putIndexMapping(Map<String, Object> context, String nodeName, String indexName, String type, XContentBuilder mappingBuilder) throws ElasticsearchException, Exception { PutMappingResponse response = admin(context, nodeName).indices() .preparePutMapping(indexName) .setType(type) .setSource(mappingBuilder) .execute().actionGet(); if (!response.isAcknowledged()) { throw new Exception("Could not put mapping [" + type + "] for index [" + indexName + "]"); } }
/** * Put index mapping * * @param context * @param nodeName * @param indexName * @param type * @param mappingBuilder * @throws ElasticsearchException * @throws Exception */ private void putIndexMapping(Map<String, Object> context, String nodeName, String indexName, String type, XContentBuilder mappingBuilder) throws ElasticsearchException, Exception { PutMappingResponse response = admin(context, nodeName).indices() .preparePutMapping(indexName) .setType(type) .setSource(mappingBuilder) .execute().actionGet(); if (!response.isAcknowledged()) { throw new Exception("Could not put mapping [" + type + "] for index [" + indexName + "]"); } }
private void createMappings(Client client, OntologyTermIndexRepository ontologyTermIndexRepository) throws IOException { String documentType = MapperTypeSanitizer.sanitizeMapperType(ontologyTermIndexRepository.getName()); XContentBuilder jsonBuilder = MappingsBuilder.buildMapping(ontologyTermIndexRepository); logger.info("Going to create mapping [" + jsonBuilder.string() + "]"); PutMappingResponse response = client.admin().indices().preparePutMapping("molgenis").setType(documentType) .setSource(jsonBuilder).execute().actionGet(); if (!response.isAcknowledged()) { throw new ElasticsearchException("Creation of mapping for documentType [PalgaSample] failed. Response=" + response); } logger.info("Mapping for documentType [" + documentType + "] created"); }
@Override public boolean putMapping(String indexName, String type, Object mappings) { Assert.notNull(indexName, "No index defined for putMapping()"); Assert.notNull(type, "No type defined for putMapping()"); PutMappingRequestBuilder requestBuilder = getIndicesAdminClient().preparePutMapping(indexName).setType(type); if (mappings instanceof String) { requestBuilder.setSource(String.valueOf(mappings), XContentType.JSON); } else if (mappings instanceof Map) { requestBuilder.setSource((Map) mappings); } else if (mappings instanceof XContentBuilder) { requestBuilder.setSource((XContentBuilder) mappings); } return requestBuilder.execute().actionGet().isAcknowledged(); }
public void open() { final IndicesExistsResponse existsResponse = client.admin().indices() .prepareExists(index).execute().actionGet(); if (!existsResponse.isExists()) { final CreateIndexResponse createIndexResponse = client.admin() .indices().prepareCreate(index).execute().actionGet(); if (!createIndexResponse.isAcknowledged()) { throw new TasteException("Failed to create " + index + " index."); } } if (mappingBuilder != null) { final GetMappingsResponse response = client.admin().indices() .prepareGetMappings(index).setTypes(type).execute() .actionGet(); if (response.mappings().isEmpty()) { final PutMappingResponse putMappingResponse = client.admin() .indices().preparePutMapping(index).setType(type) .setSource(mappingBuilder).execute().actionGet(); if (!putMappingResponse.isAcknowledged()) { throw new TasteException("Failed to create a mapping of" + index + "/" + type); } } } }
@Override public Table execute() throws MetaModelException { final MutableTable table = getTable(); final Map<String, ?> source = ElasticSearchUtils.getMappingSource(table); final ElasticSearchDataContext dataContext = getUpdateCallback().getDataContext(); final IndicesAdminClient indicesAdmin = dataContext.getElasticSearchClient().admin().indices(); final String indexName = dataContext.getIndexName(); final PutMappingRequestBuilder requestBuilder = new PutMappingRequestBuilder(indicesAdmin, PutMappingAction.INSTANCE).setIndices(indexName) .setType(table.getName()); requestBuilder.setSource(source); final PutMappingResponse result = requestBuilder.execute().actionGet(); logger.debug("PutMapping response: acknowledged={}", result.isAcknowledged()); dataContext.getElasticSearchClient().admin().indices().prepareRefresh(indexName).get(); final MutableSchema schema = (MutableSchema) getSchema(); schema.addTable(table); return table; }
@Override public Table execute() throws MetaModelException { final MutableTable table = getTable(); final Map<String, ?> source = ElasticSearchUtils.getMappingSource(table); final ElasticSearchDataContext dataContext = getUpdateCallback().getDataContext(); final IndicesAdminClient indicesAdmin = dataContext.getElasticSearchClient().admin().indices(); final String indexName = dataContext.getIndexName(); final PutMappingRequestBuilder requestBuilder = new PutMappingRequestBuilder(indicesAdmin, PutMappingAction.INSTANCE).setIndices(indexName) .setType(table.getName()); requestBuilder.setSource(source); final PutMappingResponse result = requestBuilder.execute().actionGet(); logger.debug("PutMapping response: acknowledged={}", result.isAcknowledged()); dataContext.getElasticSearchClient().admin().indices().prepareRefresh(indexName).get(); final MutableSchema schema = (MutableSchema) getSchema(); schema.addTable(table); return table; }
.setSource(entry.getValue().getAttributes()) .get(); if (!mappingResponse.isAcknowledged()) { throw new IllegalStateException("Failed to create type " + entry.getKey());