@Override public String toString() { StringBuilder message = new StringBuilder(); message.append("ES put mapping request"); if (request.indices().length > 0) { message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ","))); } String type = request.type(); if (type != null) { message.append(String.format(" on type '%s'", type)); } String source = request.source(); if (source != null) { message.append(String.format(" with source '%s'", source)); } return message.toString(); } }
/** * 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" ); } }
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); }; }
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());
setIgnoreConflicts(false).setType(store).setSource(mapping).execute().actionGet(); } catch (Exception e) { throw convert(e);
private void addMappingToIndex(String indexName, String mappingType, String mappingFilename) throws IOException { GetMappingsResponse getMappingsResponse = elasticSearchClient.admin() .indices() .prepareGetMappings(indexName) .addTypes(mappingType) .execute() .actionGet(); if (getMappingsResponse.mappings().isEmpty()) { logger.info("Adding the workflow type mappings"); InputStream stream = ElasticSearchDAOV5.class.getResourceAsStream(mappingFilename); byte[] bytes = IOUtils.toByteArray(stream); String source = new String(bytes); try { elasticSearchClient.admin() .indices() .preparePutMapping(indexName) .setType(mappingType) .setSource(source) .execute() .actionGet(); } catch (Exception e) { logger.error("Failed to init index mappings", 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}}'"); }
@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 mapping) { Assert.notNull(indexName, "No index defined for putMapping()"); Assert.notNull(type, "No type defined for putMapping()"); PutMappingRequest request = new PutMappingRequest(indexName).type(type); if (mapping instanceof String) { request.source(String.valueOf(mapping), XContentType.JSON); } else if (mapping instanceof Map) { request.source((Map) mapping); } else if (mapping instanceof XContentBuilder) { request.source((XContentBuilder) mapping); } try { return client.indices().putMapping(request).isAcknowledged(); } catch (IOException e) { throw new ElasticsearchException("Failed to put mapping for " + indexName, e); } }
@Test public void get_with_string_timeout_is_not_yet_implemented() { try { es.client().preparePutMapping().get("1"); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
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 {
/** * 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" ); } }
@Test public void trace_logs() { logTester.setLevel(LoggerLevel.TRACE); PutMappingRequestBuilder requestBuilder = es.client().preparePutMapping(FakeIndexDefinition.INDEX) .setType(FakeIndexDefinition.TYPE) .setSource(mapDomain()); requestBuilder.get(); assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1); }
@Test public void execute_should_throw_an_unsupported_operation_exception() { try { es.client().preparePutMapping().execute(); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous"); } }
tc.admin().indices().create(new CreateIndexRequest("u")).actionGet(); tc.admin().indices().putMapping(new PutMappingRequest("a").type("b") .source("_source","enabled=false","content","store=true,type=text","field1","store=true,type=text", "field2","store=true,type=text", "a","store=true,type=text", "b","store=true,type=text", "my.nested.field","store=true,type=text") ).actionGet(); tc.admin().indices().putMapping(new PutMappingRequest("c").type("d") .source("_source","enabled=false","content","store=true,type=text","field1","store=true,type=text", "field2","store=true,type=text", "a","store=true,type=text", "b","store=true,type=text", "my.nested.field","store=true,type=text") ).actionGet(); tc.admin().indices().putMapping(new PutMappingRequest("test").type("type1") .source("_source","enabled=false","content","store=true,type=text","field1","store=true,type=text", "field2","store=true,type=text", "a","store=true,type=text", "b","store=true,type=text", "my.nested.field","store=true,type=text") ).actionGet(); tc.admin().indices().putMapping(new PutMappingRequest("u").type("b") .source("_source","enabled=false","content","store=true,type=text","field1","store=true,type=text", "field2","store=true,type=text", "a","store=true,type=text", "b","store=true,type=text", "my.nested.field","store=true,type=text") ).actionGet();
@Test public void fail_on_bad_query() { try { es.client().preparePutMapping().get(); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class); assertThat(e.getMessage()).contains("Fail to execute ES put mapping request"); } }
.setType(entry.getKey()) .setSource(entry.getValue().getAttributes()) .get(); if (!mappingResponse.isAcknowledged()) { throw new IllegalStateException("Failed to create type " + entry.getKey());
tc.admin().indices().putMapping(new PutMappingRequest("test").type("typex").source("fieldx","type=text")).actionGet(); Assert.fail(); } catch (ElasticsearchSecurityException e) {
@Test public void get_with_time_value_timeout_is_not_yet_implemented() { try { es.client().preparePutMapping().get(TimeValue.timeValueMinutes(1)); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }