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); }; }
@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()); } } }
/** * 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" ); } }
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); } } }
/** * 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 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"); } }
setIgnoreConflicts(false).setType(store).setSource(mapping).execute().actionGet(); } catch (Exception e) { throw convert(e);
public void setMapping(String indexName, File json) { try { this.elasticsearchClient.admin().indices().preparePutMapping(indexName) .setSource(new String(Files.readAllBytes(json.toPath()), StandardCharsets.UTF_8), XContentType.JSON) .setUpdateAllTypes(true) .setType("_default_") .execute() .actionGet(); } catch (Throwable e) { Data.logger.warn("", e); }; }
public void setMapping(String indexName, Map<String, Object> mapping) { try { this.elasticsearchClient.admin().indices().preparePutMapping(indexName) .setSource(mapping) .setUpdateAllTypes(true) .setType("_default_").execute().actionGet(); } catch (Throwable e) { Data.logger.warn("", e); }; }
public void setMapping(String indexName, String mapping) { try { this.elasticsearchClient.admin().indices().preparePutMapping(indexName) .setSource(mapping, XContentType.JSON) .setUpdateAllTypes(true) .setType("_default_").execute().actionGet(); } catch (Throwable e) { Data.logger.warn("", e); }; }
public void setMapping(String indexName, XContentBuilder mapping) { try { this.elasticsearchClient.admin().indices().preparePutMapping(indexName) .setSource(mapping) .setUpdateAllTypes(true) .setType("_default_").execute().actionGet(); } catch (Throwable e) { Data.logger.warn("", e); }; }
public void recreateIndex() throws IOException { deleteIndex(); final Client client = this.getClient(); final InputStream mappings = Thread.currentThread().getContextClassLoader() .getResourceAsStream("mappings.json"); final InputStream index_settings = Thread.currentThread().getContextClassLoader() .getResourceAsStream("index_settings.json"); String mappingsString = IOUtils.toString(mappings); JSONObject mappingsJSON = new JSONObject(mappingsString); // add all langs to the mapping mappingsJSON = addLangsToMapping(mappingsJSON); client.admin().indices().prepareCreate("photon").setSettings(IOUtils.toString(index_settings)).execute() .actionGet(); client.admin().indices().preparePutMapping("photon").setType("place").setSource(mappingsJSON.toString()) .execute().actionGet(); log.info("mapping created: " + mappingsJSON.toString()); }
.execute(new ActionListener<AcknowledgedResponse>() { @Override public void onResponse(AcknowledgedResponse putMappingResponse) {
@SuppressWarnings("rawtypes") private void createMapping(String indexName, String indexType, Map json) { if (json != null) { client.admin().indices().preparePutMapping(indexName).setType(indexType).setSource(json).execute() .actionGet(); } } }
private void addMapping(String type, XContentBuilder mapping) { esResource .getClient() .admin() .indices() .preparePutMapping(index) .setType(type) .setSource(mapping) .execute() .actionGet(); }
/** Add a mapping to Elasticsearch. This will only be called if a new index has been created */ public void addMapping(XContentBuilder mapping) { esResource .getClient() .admin() .indices() .preparePutMapping(index) .setType(type) .setSource(mapping) .execute() .actionGet(); }
@Override public void addMapping(XContentBuilder mapping) { esResource .getClient() .admin() .indices() .preparePutMapping(index) .setType(type) .setSource(mapping) .execute() .actionGet(); }
private static class StreamingPropertyString { private final String propertyValue; public StreamingPropertyString(String propertyValue) { this.propertyValue = propertyValue; } public String getPropertyValue() { return propertyValue; } }
// 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();
@Override public <T> boolean putMapping(Class<T> clazz) { ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz); PutMappingRequestBuilder requestBuilder = client.admin().indices().preparePutMapping(persistentEntity.getIndexName()) .setType(persistentEntity.getIndexType()); try { XContentBuilder xContentBuilder = buildMapping(clazz, persistentEntity.getIndexType(), persistentEntity.getIdProperty().getFieldName()); return requestBuilder.setSource(xContentBuilder).execute().actionGet().acknowledged(); } catch (Exception e) { throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName() , e); } }