public void setMapping(String indexName, File json) { try { this.elasticsearchClient.admin().indices().preparePutMapping(indexName) .setSource(new String(Files.readAllBytes(json.toPath()), StandardCharsets.UTF_8)) .setUpdateAllTypes(true) .setType("_default_") .execute() .actionGet(); } catch (Throwable e) { DAO.severe(e); }; }
if (!esClient.admin().indices().prepareExists(definition.getIndexName()).get().isExists()) { esClient.admin().indices().prepareCreate(definition.getIndexName()).get(); logger.debug("Set explicit attachment mapping."); esClient.admin().indices().preparePutMapping(definition.getIndexName()).setType(definition.getTypeName()) .setSource(getGridFSMapping()).get(); } catch (Exception e) { logger.warn("Failed to set explicit mapping (attachment): {}", e);
@Test public void to_string() { assertThat(es.client().preparePutMapping(FakeIndexDefinition.INDEX).setSource(mapDomain()).toString()) .isEqualTo("ES put mapping request on indices 'fakes' with source '{\"dynamic\":false,\"_all\":{\"enabled\":false}}'"); assertThat(es.client().preparePutMapping(FakeIndexDefinition.INDEX).setType(FakeIndexDefinition.TYPE).setSource(mapDomain()).toString()) .isEqualTo("ES put mapping request on indices 'fakes' on type 'fake' with source '{\"dynamic\":false,\"_all\":{\"enabled\":false}}'"); }
CreateIndexResponse indexResponse = SHARED_NODE.client().admin().indices() .prepareCreate(index.getName()) .setSettings(settings) .get(); throw new IllegalStateException("Failed to create index " + index.getName()); SHARED_NODE.client().admin().cluster().prepareHealth(index.getName()).setWaitForStatus(ClusterHealthStatus.YELLOW).get(); PutMappingResponse mappingResponse = SHARED_NODE.client().admin().indices().preparePutMapping(index.getName()) .setType(entry.getKey()) .setSource(entry.getValue().getAttributes()) .get(); if (!mappingResponse.isAcknowledged()) { throw new IllegalStateException("Failed to create type " + entry.getKey());
@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; }
semaphore.acquire(); logger.trace("dropRecreateMapping index[{}] - type[{}]", index, type); client.admin().indices().prepareRefresh(index).get(); ImmutableOpenMap<String, MappingMetaData> mappings = client.admin().cluster().prepareState().get().getState().getMetaData() .index(index).mappings(); logger.trace("mappings contains type {}: {}", type, mappings.containsKey(type)); if (client.admin().indices().prepareDeleteMapping(index).setType(type).get().isAcknowledged()) { 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 {
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 protected void loadData() throws Exception { client.admin().indices().preparePutMapping("test").setType("type1").setSource("{\"type1\":{"+ " \"properties\" : { "+ " \"tag\" : {\"type\" : \"string\", \"analyzer\" : \"hsf_analyzer\"} "+ " } "+ "}}" ).execute().actionGet(); client.prepareIndex("test", "type1") .setSource("{ \"tag\" : \"1s2s3\"}").execute().actionGet(); client.admin().indices().prepareFlush().setRefresh(true).execute() .actionGet(); client.prepareIndex("test", "type1") .setSource("{ \"tag\" : \"2s4\"}").execute().actionGet(); client.admin().indices().prepareRefresh().execute().actionGet(); }
createIndexRequest.cause("auto(task api)"); client.admin().indices().create(createIndexRequest, new ActionListener<CreateIndexResponse>() { @Override public void onResponse(CreateIndexResponse result) { if (getTaskResultMappingVersion(metaData) < TASK_RESULT_MAPPING_VERSION) { client.admin().indices().preparePutMapping(TASK_INDEX).setType(TASK_TYPE) .setSource(taskResultIndexMapping(), XContentType.JSON) .execute(new ActionListener<AcknowledgedResponse>() { @Override public void onResponse(AcknowledgedResponse putMappingResponse) {
@PostConstruct private void createIndexWithMapping() { IndicesAdminClient indicesAdminClient = transportClient.admin().indices(); IndicesExistsRequest request = new IndicesExistsRequest(props.getIndex().getName()); IndicesExistsResponse indicesExistsResponse = indicesAdminClient.exists(request).actionGet(); indicesAdminClient.prepareCreate(props.getIndex().getName()) .setSettings(Settings.builder() .put("index.number_of_shards", props.getIndex().getShard()) .endObject(); indicesAdminClient.preparePutMapping(props.getIndex().getName()) .setType(props.getIndex().getType()) .setSource(builder.string(), XContentType.JSON) .get(); } catch (IOException ex){ log.error("The exception was thrown in createIndexWithMapping method. {} ", ex);
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; }
@Override public PutMappingResponse get() { Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start(); try { return super.execute().actionGet(); } catch (Exception e) { throw new IllegalStateException(String.format("Fail to execute %s", toString()), e); } finally { if (profiler.isTraceEnabled()) { profiler.stopTrace(toString()); } } }
@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(); }
PutMappingRequestBuilder pmrb = client.admin().indices() .preparePutMapping(index) .setType(type); pmrb.setSource(source); MappingListener mappingListener = new MappingListener(pmrb) if (response.isAcknowledged()) { System.out.println("template successfully applied")
LOGGER.info(String.format("Create type %s/%s", index.getName(), entry.getKey())); PutMappingResponse mappingResponse = client.preparePutMapping(index.getName()) .setType(entry.getKey()) .setSource(entry.getValue().getAttributes()) .get(); if (!mappingResponse.isAcknowledged()) { throw new IllegalStateException("Failed to create type " + entry.getKey());
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); }
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 + " ]."); }
public void putMappingFromString(String index, String type, String mapping) { IndicesAdminClient iac = getClient().admin().indices(); PutMappingRequestBuilder pmrb = new PutMappingRequestBuilder(iac); pmrb.setIndices(index); pmrb.setType(type); pmrb.setSource(mapping); ListenableActionFuture<PutMappingResponse> laf = pmrb.execute(); PutMappingResponse pmr = laf.actionGet(); pmr.getAcknowledged(); }
// Index (and mapping) do not exist CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate("indexName"); createIndexRequestBuilder.addMapping("typeName", mapping); response = createIndexRequestBuilder.execute().actionGet(); // Index exists but not mapping PutMappingRequestBuilder preparePutMappingBuilder = client.admin().indices().preparePutMapping("indexName"); preparePutMappingBuilder.setSource(mapping).setType("typeName"); response = preparePutMappingBuilder.execute().actionGet();