org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder Java Examples
The following examples show how to use
org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MappingUpdatedAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
public void updateMappingOnMaster(String index, String type, Mapping mappingUpdate, final TimeValue timeout, final MappingUpdateListener listener) { final PutMappingRequestBuilder request = updateMappingRequest(index, type, mappingUpdate, timeout); if (listener == null) { request.execute(); } else { final ActionListener<PutMappingResponse> actionListener = new ActionListener<PutMappingResponse>() { @Override public void onResponse(PutMappingResponse response) { if (response.isAcknowledged()) { listener.onMappingUpdate(); } else { listener.onFailure(new TimeoutException("Failed to acknowledge the mapping response within [" + timeout + "]")); } } @Override public void onFailure(Throwable e) { listener.onFailure(e); } }; request.execute(actionListener); } }
Example #2
Source File: IndexUpdateMapping.java From sfs with Apache License 2.0 | 6 votes |
@Override public Observable<Boolean> call(String index) { Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch(); PutMappingRequestBuilder request = elasticsearch.get().admin().indices() .preparePutMapping(index) .setSource(mapping) .setType(type); if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Request %s", Jsonify.toString(request))); } return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout()) .map(Optional::get) .doOnNext(putMappingResponse -> { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Response %s", Jsonify.toString(putMappingResponse))); } }) .map(AcknowledgedResponse::isAcknowledged); }
Example #3
Source File: DefaultElasticSearchAdminService.java From vertx-elasticsearch-service with Apache License 2.0 | 6 votes |
@Override public void putMapping(List<String> indices, String type, JsonObject source, MappingOptions options, Handler<AsyncResult<Void>> resultHandler) { final PutMappingRequestBuilder builder = PutMappingAction.INSTANCE.newRequestBuilder(service.getClient()) .setIndices(indices.toArray(new String[indices.size()])) .setType(type) .setSource(source.encode(), XContentType.JSON); builder.execute(new ActionListener<PutMappingResponse>() { @Override public void onResponse(PutMappingResponse putMappingResponse) { resultHandler.handle(Future.succeededFuture()); } @Override public void onFailure(Exception e) { resultHandler.handle(Future.failedFuture(e)); } }); }
Example #4
Source File: InternalEsClient.java From io with Apache License 2.0 | 5 votes |
/** * Mapping定義を更新する. * @param index インデックス名 * @param type タイプ名 * @param mappings マッピング情報 * @return 非同期応答 */ public ListenableActionFuture<PutMappingResponse> putMapping(String index, String type, Map<String, Object> mappings) { PutMappingRequestBuilder builder = new PutMappingRequestBuilder(esTransportClient.admin().indices()) .setIndices(index) .setType(type) .setSource(mappings); return builder.execute(); }
Example #5
Source File: MappingUpdatedAction.java From crate with Apache License 2.0 | 5 votes |
private PutMappingRequestBuilder updateMappingRequest(Index index, String type, Mapping mappingUpdate, final TimeValue timeout) { if (type.equals(MapperService.DEFAULT_MAPPING)) { throw new IllegalArgumentException("_default_ mapping should not be updated"); } return client.preparePutMapping().setConcreteIndex(index).setType(type).setSource(mappingUpdate.toString(), XContentType.JSON) .setMasterNodeTimeout(timeout).setTimeout(timeout); }
Example #6
Source File: UpgradeUtil.java From fess with Apache License 2.0 | 5 votes |
public static boolean putMapping(final IndicesAdminClient indicesClient, final String index, final String type, final String source) { try { final PutMappingRequestBuilder builder = indicesClient.preparePutMapping(index).setSource(source, XContentType.JSON); final AcknowledgedResponse pmResponse = builder.execute().actionGet(); if (!pmResponse.isAcknowledged()) { logger.warn("Failed to update {} settings.", index); } else { return true; } } catch (final Exception e) { logger.warn("Failed to update " + index + " settings.", e); } return false; }
Example #7
Source File: HttpBulkNodeClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override public HttpBulkNodeClient newMapping(String index, String type, Map<String, Object> mapping) { PutMappingRequestBuilder putMappingRequestBuilder = new PutMappingRequestBuilder(client(), PutMappingAction.INSTANCE) .setIndices(index) .setType(type) .setSource(mapping); putMappingRequestBuilder.execute().actionGet(); logger.info("mapping created for index {} and type {}", index, type); return this; }
Example #8
Source File: BulkNodeClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override public BulkNodeClient newMapping(String index, String type, Map<String, Object> mapping) { PutMappingRequestBuilder putMappingRequestBuilder = new PutMappingRequestBuilder(client(), PutMappingAction.INSTANCE) .setIndices(index) .setType(type) .setSource(mapping); putMappingRequestBuilder.execute().actionGet(); logger.info("mapping created for index {} and type {}", index, type); return this; }
Example #9
Source File: BaseMetricTransportClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override public BaseMetricTransportClient newMapping(String index, String type, Map<String, Object> mapping) { new PutMappingRequestBuilder(client(), PutMappingAction.INSTANCE) .setIndices(index) .setType(type) .setSource(mapping) .execute().actionGet(); logger.info("mapping created for index {} and type {}", index, type); return this; }
Example #10
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 5 votes |
public AcknowledgedResponse createMapping(final String index, final BuilderCallback<PutMappingRequestBuilder> builder) { final AcknowledgedResponse actionGet = builder.apply(client().admin().indices().preparePutMapping(index)).execute().actionGet(); if (!actionGet.isAcknowledged()) { onFailure("Failed to create a mapping for " + index + ".", actionGet); } return actionGet; }
Example #11
Source File: InternalEsClient.java From io with Apache License 2.0 | 5 votes |
/** * Mapping定義を更新する. * @param index インデックス名 * @param type タイプ名 * @param mappings マッピング情報 * @return 非同期応答 */ public ListenableActionFuture<PutMappingResponse> putMapping(String index, String type, Map<String, Object> mappings) { PutMappingRequestBuilder builder = new PutMappingRequestBuilder(esTransportClient.admin().indices(), PutMappingAction.INSTANCE) .setIndices(index) .setType(type) .setSource(mappings); return builder.execute(); }
Example #12
Source File: ElasticsearchClient.java From hawkular-apm with Apache License 2.0 | 5 votes |
/** * This method applies the supplied mapping to the index. * * @param index The name of the index * @param defaultMappings The default mappings * @return true if the mapping was successful */ @SuppressWarnings("unchecked") private boolean prepareMapping(String index, Map<String, Object> defaultMappings) { boolean success = true; for (Map.Entry<String, Object> stringObjectEntry : defaultMappings.entrySet()) { Map<String, Object> mapping = (Map<String, Object>) stringObjectEntry.getValue(); if (mapping == null) { throw new RuntimeException("type mapping not defined"); } PutMappingRequestBuilder putMappingRequestBuilder = client.admin().indices().preparePutMapping() .setIndices(index); putMappingRequestBuilder.setType(stringObjectEntry.getKey()); putMappingRequestBuilder.setSource(mapping); if (log.isLoggable(Level.FINE)) { log.fine("Elasticsearch create mapping for index '" + index + " and type '" + stringObjectEntry.getKey() + "': " + mapping); } PutMappingResponse resp = putMappingRequestBuilder.execute().actionGet(); if (resp.isAcknowledged()) { if (log.isLoggable(Level.FINE)) { log.fine("Elasticsearch mapping for index '" + index + " and type '" + stringObjectEntry.getKey() + "' was acknowledged"); } } else { success = false; log.warning("Elasticsearch mapping creation was not acknowledged for index '" + index + " and type '" + stringObjectEntry.getKey() + "'"); } } return success; }
Example #13
Source File: MappingUpdatedAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
private PutMappingRequestBuilder updateMappingRequest(String index, String type, Mapping mappingUpdate, final TimeValue timeout) { if (type.equals(MapperService.DEFAULT_MAPPING)) { throw new IllegalArgumentException("_default_ mapping should not be updated"); } return client.preparePutMapping(index).setType(type).setSource(mappingUpdate.toString()) .setMasterNodeTimeout(timeout).setTimeout(timeout); }
Example #14
Source File: AbstractClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public PutMappingRequestBuilder preparePutMapping(String... indices) { return new PutMappingRequestBuilder(this, PutMappingAction.INSTANCE).setIndices(indices); }
Example #15
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public PutMappingRequestBuilder preparePutMapping(String... indices) { return new PutMappingRequestBuilder(this, PutMappingAction.INSTANCE).setIndices(indices); }
Example #16
Source File: IndicesAdminClient.java From crate with Apache License 2.0 | 2 votes |
/** * Add mapping definition for a type into one or more indices. */ PutMappingRequestBuilder preparePutMapping(String... indices);
Example #17
Source File: IndicesAdminClient.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Add mapping definition for a type into one or more indices. */ PutMappingRequestBuilder preparePutMapping(String... indices);