本文整理了Java中org.elasticsearch.client.IndicesAdminClient.prepareCreate()
方法的一些代码示例,展示了IndicesAdminClient.prepareCreate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IndicesAdminClient.prepareCreate()
方法的具体详情如下:
包路径:org.elasticsearch.client.IndicesAdminClient
类名称:IndicesAdminClient
方法名:prepareCreate
[英]Creates an index using an explicit request allowing to specify the settings of the index.
[中]使用允许指定索引设置的显式请求创建索引。
代码示例来源:origin: Netflix/conductor
private void updateLogIndexName() {
this.logIndexName = this.logIndexPrefix + "_" + SIMPLE_DATE_FORMAT.format(new Date());
try {
elasticSearchClient.admin()
.indices()
.prepareGetIndex()
.addIndices(logIndexName)
.execute()
.actionGet();
} catch (IndexNotFoundException infe) {
try {
elasticSearchClient.admin()
.indices()
.prepareCreate(logIndexName)
.execute()
.actionGet();
} catch (ResourceAlreadyExistsException ilee) {
// no-op
} catch (Exception e) {
logger.error("Failed to update log index name: {}", logIndexName, e);
}
}
}
代码示例来源:origin: Netflix/conductor
private void addIndex(String indexName) {
try {
elasticSearchClient.admin()
.indices()
.prepareGetIndex()
.addIndices(indexName)
.execute()
.actionGet();
} catch (IndexNotFoundException infe) {
try {
elasticSearchClient.admin()
.indices()
.prepareCreate(indexName)
.execute()
.actionGet();
} catch (ResourceAlreadyExistsException done) {
// no-op
}
}
}
代码示例来源:origin: loklak/loklak_server
public void createIndexIfNotExists(String indexName, final int shards, final int replicas) {
// create an index if not existent
if (!this.elasticsearchClient.admin().indices().prepareExists(indexName).execute().actionGet().isExists()) {
Settings.Builder settings = Settings.builder()
.put("number_of_shards", shards)
.put("number_of_replicas", replicas);
this.elasticsearchClient.admin().indices().prepareCreate(indexName)
.setSettings(settings)
.setUpdateAllTypes(true)
.execute().actionGet();
} else {
//LOGGER.debug("Index with name {} already exists", indexName);
}
}
代码示例来源:origin: thinkaurelius/titan
/**
* If ES already contains this instance's target index, then do nothing.
* Otherwise, create the index, then wait {@link #CREATE_SLEEP}.
* <p>
* The {@code client} field must point to a live, connected client.
* The {@code indexName} field must be non-null and point to the name
* of the index to check for existence or create.
*
* @param config the config for this ElasticSearchIndex
* @throws java.lang.IllegalArgumentException if the index could not be created
*/
private void checkForOrCreateIndex(Configuration config) {
Preconditions.checkState(null != client);
//Create index if it does not already exist
IndicesExistsResponse response = client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet();
if (!response.isExists()) {
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
ElasticSearchSetup.applySettingsFromTitanConf(settings, config, ES_CREATE_EXTRAS_NS);
CreateIndexResponse create = client.admin().indices().prepareCreate(indexName)
.setSettings(settings.build()).execute().actionGet();
try {
final long sleep = config.get(CREATE_SLEEP);
log.debug("Sleeping {} ms after {} index creation returned from actionGet()", sleep, indexName);
Thread.sleep(sleep);
} catch (InterruptedException e) {
throw new TitanException("Interrupted while waiting for index to settle in", e);
}
if (!create.isAcknowledged()) throw new IllegalArgumentException("Could not create index: " + indexName);
}
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public void recreateIndex(String indexName)
throws IOException {
DeleteIndexRequestBuilder dirBuilder = transportClient.admin().indices().prepareDelete(indexName);
try {
DeleteIndexResponse diResponse = dirBuilder.execute().actionGet();
} catch (IndexNotFoundException ie) {
System.out.println("Index not found... that's ok");
}
CreateIndexRequestBuilder cirBuilder = transportClient.admin().indices().prepareCreate(indexName);
CreateIndexResponse ciResponse = cirBuilder.execute().actionGet();
Assert.assertTrue(ciResponse.isAcknowledged(), "Create index succeeeded");
}
代码示例来源:origin: apache/usergrid
final CreateIndexResponse cir = admin.indices().prepareCreate(indexName)
.setSettings(settings)
.execute()
代码示例来源:origin: SonarSource/sonarqube
settings.put(index.getSettings());
CreateIndexResponse indexResponse = SHARED_NODE.client().admin().indices()
.prepareCreate(index.getName())
.setSettings(settings)
.get();
代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb
esClient.admin().indices().prepareCreate(definition.getIndexName()).get();
代码示例来源:origin: komoot/photon
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());
}
代码示例来源:origin: yacy/yacy_grid_mcp
/**
* create a new index. This method must be called to ensure that an elasticsearch index is available and can be used.
* @param indexName
* @param shards
* @param replicas
* @throws NoNodeAvailableException in case that no elasticsearch server can be contacted.
*/
public void createIndexIfNotExists(String indexName, final int shards, final int replicas) throws NoNodeAvailableException {
// create an index if not existent
if (!this.elasticsearchClient.admin().indices().prepareExists(indexName).execute().actionGet().isExists()) {
Settings.Builder settings = Settings.builder()
.put("number_of_shards", shards)
.put("number_of_replicas", replicas);
this.elasticsearchClient.admin().indices().prepareCreate(indexName)
.setSettings(settings)
.setUpdateAllTypes(true)
.execute().actionGet();
} else {
//LOGGER.debug("Index with name {} already exists", indexName);
}
}
代码示例来源:origin: apache/metron
public void createIndexWithMapping(String indexName, String mappingType, String mappingSource)
throws IOException {
CreateIndexResponse cir = client.admin().indices().prepareCreate(indexName)
.addMapping(mappingType, mappingSource)
.get();
if (!cir.isAcknowledged()) {
throw new IOException("Create index was not acknowledged");
}
}
代码示例来源:origin: larsga/Duke
.prepareCreate(indexName).execute().actionGet();
try {
Thread.sleep(200);
代码示例来源:origin: apache/metron
client.admin().indices().prepareCreate(m.index)
.addMapping(m.docType, m.mapping).get();
代码示例来源:origin: hmsonline/storm-elastic-search
private void createIndex(String indexName, Settings indicesSettings) {
if (indicesSettings != null) {
client.admin().indices().prepareCreate(indexName).setSettings(indicesSettings).execute().actionGet();
} else {
client.admin().indices().prepareCreate(indexName).execute().actionGet();
}
}
代码示例来源:origin: hmsonline/storm-elastic-search
private void createIndex(BulkRequestBuilder bulkRequest, String indexName, Settings indicesSettings) {
try {
if (indicesSettings != null) {
client.admin().indices().prepareCreate(indexName).setSettings(indicesSettings).execute().actionGet();
} else {
client.admin().indices().prepareCreate(indexName).execute().actionGet();
}
} catch (ElasticSearchException e) {
StormElasticSearchUtils.handleElasticSearchException(getClass(), e);
}
}
代码示例来源:origin: com.strapdata.elasticsearch.test/framework
/**
* Create a new index on the singleton node with the provided index settings.
*/
protected IndexService createIndex(String index, Settings settings, String type, XContentBuilder mappings) {
CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings);
if (type != null && mappings != null) {
createIndexRequestBuilder.addMapping(type, mappings);
}
return createIndex(index, createIndexRequestBuilder);
}
代码示例来源:origin: com.strapdata.elasticsearch.test/framework
/**
* Create a new index on the singleton node with the provided index settings.
*/
protected IndexService createIndex(String index, Settings settings, String type, Object... mappings) {
CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings);
if (type != null && mappings != null) {
createIndexRequestBuilder.addMapping(type, mappings);
}
return createIndex(index, createIndexRequestBuilder);
}
代码示例来源:origin: ff4j/ff4j
private void initNativeClient() {
esClient = NodeBuilder.nodeBuilder().client(true).node().client();
boolean indexExists = esClient.admin().indices().prepareExists(indexName).execute().actionGet().isExists();
if (indexExists) {
esClient.admin().indices().prepareDelete(indexName).execute().actionGet();
}
esClient.admin().indices().prepareCreate(indexName).execute().actionGet();
}
代码示例来源:origin: allegro/hermes
private void createIndexIfNeeded(IndexFactory indexFactory) {
IndicesExistsResponse response =
client.admin().indices().exists(new IndicesExistsRequest(indexFactory.createIndex())).actionGet();
if (response.isExists()) {
return;
}
client.admin().indices().prepareCreate(indexFactory.createIndex()).execute().actionGet();
}
代码示例来源:origin: dqeasycloud/easy-cloud
@Override
public boolean createIndex(String indexName, Object settings) {
CreateIndexRequestBuilder createIndexRequestBuilder = getIndicesAdminClient().prepareCreate(indexName);
if (settings instanceof String) {
createIndexRequestBuilder.setSettings(String.valueOf(settings), XContentType.JSON);
} else if (settings instanceof Map) {
createIndexRequestBuilder.setSettings((Map) settings);
} else if (settings instanceof XContentBuilder) {
createIndexRequestBuilder.setSettings((XContentBuilder) settings);
}
return createIndexRequestBuilder.execute().actionGet().isAcknowledged();
}
内容来源于网络,如有侵权,请联系作者删除!