本文整理汇总了Java中org.elasticsearch.action.admin.indices.create.CreateIndexResponse类的典型用法代码示例。如果您正苦于以下问题:Java CreateIndexResponse类的具体用法?Java CreateIndexResponse怎么用?Java CreateIndexResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CreateIndexResponse类属于org.elasticsearch.action.admin.indices.create包,在下文中一共展示了CreateIndexResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
@SuppressWarnings("unused")
protected void createIndex(String indexName) throws IOException {
CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName)
.setSettings(Settings.builder()
.put("number_of_shards", getConfig().getNumberOfShards())
.put("number_of_replicas", getConfig().getNumberOfReplicas())
)
.execute().actionGet();
ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName)
.setWaitForGreenStatus()
.execute().actionGet();
LOGGER.debug("Index status: %s", health.toString());
if (health.isTimedOut()) {
LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName);
}
}
示例2: prepareRequest
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index"));
if (request.hasContent()) {
createIndexRequest.source(request.content(), request.getXContentType());
}
createIndexRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false));
createIndexRequest.timeout(request.paramAsTime("timeout", createIndexRequest.timeout()));
createIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", createIndexRequest.masterNodeTimeout()));
createIndexRequest.waitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
return channel -> client.admin().indices().create(createIndexRequest, new AcknowledgedRestListener<CreateIndexResponse>(channel) {
@Override
public void addCustomFields(XContentBuilder builder, CreateIndexResponse response) throws IOException {
response.addCustomFields(builder);
}
});
}
示例3: testCreateIndexNoActiveShardsNoWaiting
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
public void testCreateIndexNoActiveShardsNoWaiting() throws Exception {
Settings.Builder settingsBuilder = Settings.builder()
.put(indexSettings())
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5))
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0);
if (internalCluster().getNodeNames().length > 0) {
String exclude = String.join(",", internalCluster().getNodeNames());
settingsBuilder.put("index.routing.allocation.exclude._name", exclude);
}
Settings settings = settingsBuilder.build();
CreateIndexResponse response = prepareCreate("test-idx")
.setSettings(settings)
.setWaitForActiveShards(ActiveShardCount.NONE)
.get();
assertTrue(response.isAcknowledged());
}
示例4: testCreateIndexStopsWaitingWhenIndexDeleted
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
public void testCreateIndexStopsWaitingWhenIndexDeleted() throws Exception {
final String indexName = "test-idx";
Settings settings = Settings.builder()
.put(indexSettings())
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5))
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), internalCluster().numDataNodes() - 1)
.build();
logger.info("--> start the index creation process");
ListenableActionFuture<CreateIndexResponse> responseListener =
prepareCreate(indexName)
.setSettings(settings)
.setWaitForActiveShards(ActiveShardCount.ALL)
.execute();
logger.info("--> wait until the cluster state contains the new index");
assertBusy(() -> assertTrue(client().admin().cluster().prepareState().get().getState().metaData().hasIndex(indexName)));
logger.info("--> delete the index");
assertAcked(client().admin().indices().prepareDelete(indexName));
logger.info("--> ensure the create index request completes");
assertAcked(responseListener.get());
}
示例5: test1
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
public static void test1() throws Exception{
String analyze = "{\"settings\":{\"analysis\":{\"filter\":{\"default_stopwords\":{\"type\":\"stop\",\"stopwords\":[\"a\",\"an\",\"and\",\"are\",\"as\",\"at\",\"be\",\"but\",\"by\",\"for\",\"if\",\"in\",\"into\",\"is\",\"it\",\"no\",\"not\",\"of\",\"on\",\"or\",\"such\",\"that\",\"the\",\"their\",\"then\",\"there\",\"these\",\"they\",\"this\",\"to\",\"was\",\"will\",\"with\"]}},\"char_filter\":{\"symbol_transform\":{\"mappings\":[\"&=> and \",\"||=> or \"],\"type\":\"mapping\"}},\"analyzer\":{\"es_analyzer\":{\"filter\":[\"lowercase\",\"default_stopwords\"],\"char_filter\":[\"html_strip\",\"symbol_transform\"],\"type\":\"custom\",\"tokenizer\":\"standard\"}}}}}";
Settings settings = Settings.builder().loadFromSource(analyze, XContentType.JSON).build();
// AnalysisRegistry registry = new AnalysisModule(new Environment(settings), Collections.singletonList(new AnalysisPlugin() {
// @Override
// public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
// return AnalysisPlugin.super.getTokenFilters();
// }
// @Override
// public Map<String, AnalysisProvider<TokenizerFactory>> getTokenizers() {
// return AnalysisPlugin.super.getTokenizers();
// }
// @Override
// public Map<String, AnalysisProvider<CharFilterFactory>> getCharFilters() {
// return AnalysisPlugin.super.getCharFilters();
// }
// } )).getAnalysisRegistry();
// IndexSettings idxSettings = new IndexSettings(IndexMetaData.builder("test").build(), settings);
// IndexAnalyzers indexAnalyzers = registry.build(idxSettings);
CreateIndexResponse response = tfactory.getClient().admin().indices().prepareCreate("thr2").setSettings(settings).get();
System.out.println(response.isAcknowledged());
}
示例6: testCreateIndexWithoutSettings
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
@Test
public void testCreateIndexWithoutSettings() {
// Test data
final String indexName = "Index_Name";
final AdminClient adminClient = createMock(AdminClient.class);
final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
final CreateIndexRequestBuilder createIndexRequestBuilder = createMock(CreateIndexRequestBuilder.class);
final CreateIndexResponse createIndexResponse = createMock(CreateIndexResponse.class);
// Reset
resetAll();
// Expectations
expect(esClient.admin()).andReturn(adminClient);
expect(adminClient.indices()).andReturn(indicesAdminClient);
expect(indicesAdminClient.prepareCreate(indexName)).andReturn(createIndexRequestBuilder);
expect(createIndexRequestBuilder.get()).andReturn(createIndexResponse);
// Replay
replayAll();
// Run test scenario
final boolean result = elasticsearchClientWrapper.createIndex(indexName);
// Verify
verifyAll();
assertEquals(createIndexResponse.isAcknowledged(), result);
}
示例7: testCreateIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
@Test
public void testCreateIndex() {
// Test data
final String indexName = "Index_Name";
final Map<String, Object> settings = Collections.singletonMap("settings_key", "settings_value");
final AdminClient adminClient = createMock(AdminClient.class);
final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
final CreateIndexRequestBuilder createIndexRequestBuilder = createMock(CreateIndexRequestBuilder.class);
final CreateIndexResponse createIndexResponse = createMock(CreateIndexResponse.class);
// Reset
resetAll();
// Expectations
expect(esClient.admin()).andReturn(adminClient);
expect(adminClient.indices()).andReturn(indicesAdminClient);
expect(indicesAdminClient.prepareCreate(indexName)).andReturn(createIndexRequestBuilder);
expect(createIndexRequestBuilder.setSettings(settings)).andReturn(createIndexRequestBuilder);
expect(createIndexRequestBuilder.get()).andReturn(createIndexResponse);
// Replay
replayAll();
// Run test scenario
final boolean result = elasticsearchClientWrapper.createIndex(indexName, settings);
// Verify
verifyAll();
assertEquals(createIndexResponse.isAcknowledged(), result);
}
示例8: createIndexAndExecuteUpsertRequest
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
private void createIndexAndExecuteUpsertRequest(final UpsertByIdNode.Item item,
final SettableFuture<TaskResult> futureResult) {
transportCreateIndexAction.execute(
new CreateIndexRequest(item.index()).cause("upsert single item"),
new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse createIndexResponse) {
executeUpsertRequest(item, futureResult);
}
@Override
public void onFailure(Throwable e) {
e = ExceptionsHelper.unwrapCause(e);
if (e instanceof IndexAlreadyExistsException) {
executeUpsertRequest(item, futureResult);
} else {
futureResult.setException(e);
}
}
});
}
示例9: doExecute
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
@Override
protected void doExecute(final Task task, final DeleteRequest request, final ActionListener<DeleteResponse> listener) {
ClusterState state = clusterService.state();
if (autoCreateIndex.shouldAutoCreate(request.index(), state)) {
createIndexAction.execute(task, new CreateIndexRequest(request).index(request.index()).cause("auto(delete api)")
.masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse result) {
innerExecute(task, request, listener);
}
@Override
public void onFailure(Throwable e) {
if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) {
// we have the index, do it
innerExecute(task, request, listener);
} else {
listener.onFailure(e);
}
}
});
} else {
innerExecute(task, request, listener);
}
}
示例10: index
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
/**
* http://es.xiaoleilu.com/010_Intro/25_Tutorial_Indexing.html
* http://es.xiaoleilu.com/070_Index_Mgmt/05_Create_Delete.html
* 索引相关的
*/
private static void index() throws IOException, InterruptedException {
// cluster(),产生一个允许从集群中执行action或操作的client;
IndicesAdminClient indicesAdminClient = client.admin().indices();
//创建索引
if (checkExistsIndex(indicesAdminClient, INDEX_NAME)) {
deleteIndex(indicesAdminClient, INDEX_NAME);
}
// String settings = getIndexSetting();
// CreateIndexResponse createIndexResponse = indicesAdminClient.prepareCreate(INDEX_NAME).setSettings(settings).execute().actionGet();
CreateIndexResponse createIndexResponse = indicesAdminClient.prepareCreate(INDEX_NAME).setSettings().execute().actionGet();
// log.info("创建索引{}:{}", INDEX_NAME, createIndexResponse.getContext());
//索引的相关配置操作
indexConfig(indicesAdminClient, INDEX_NAME);
// indexMapping(indicesAdminClient, INDEX_NAME, TYPE_NAME);
}
示例11: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
/**
* Create index.
*
* @return True if index create ok, false if index is already exist.
*/
public boolean createIndex() {
// check index exist:
IndicesAdminClient idc = client.admin().indices();
IndicesExistsResponse ier = idc.exists(new IndicesExistsRequest(index)).actionGet();
if (!ier.isExists()) {
log.info("Index not found. Auto-create...");
// create index:
CreateIndexResponse cir = idc.create(new CreateIndexRequest(index)).actionGet();
if (!cir.isAcknowledged()) {
throw new RuntimeException("Failed to create index.");
}
return true;
}
return false;
}
示例12: createIndexIfNotExists
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
public void createIndexIfNotExists(String index, String settingJson, Map<String, String> mappingJson) {
String formattedIndex = formatIndex(index);
IndicesAdminClient indicesClient = client.admin().indices();
IndicesExistsResponse existsResponse = indicesClient.prepareExists(formattedIndex).get();
if (existsResponse.isExists()) {
return;
}
CreateIndexRequestBuilder builder = indicesClient.prepareCreate(formattedIndex)
.setSettings(Settings.settingsBuilder().loadFromSource(settingJson));
mappingJson.forEach((k, v) -> {
builder.addMapping(k, v);
});
CreateIndexResponse indexResponse = builder.get();
if (!indexResponse.isAcknowledged()) {
throw new ElasticsearchException(String.format("index %s の作成に失敗しました", index));
}
}
示例13: testCreateIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
/**
* index作成.
*/
@Test
public void testCreateIndex() throws Exception {
// index名は英数小文字のみ。記号はハイフンであれば許容されるよう
String index = "9-1234-5";
// String index = "01test-create-index";
try {
CreateIndexResponse response = createIndex(index);
assertThat(response.isAcknowledged(), is(true));
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
// 後始末
DeleteIndexResponse deleteIndexResponse = deleteIndex(index);
assertThat(deleteIndexResponse.isAcknowledged(), is(true));
}
}
示例14: createNewIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
@Override
public void createNewIndex(String indexName) {
if (!indexExists(indexName)) {
CreateIndexRequestBuilder indexRequestBuilder = indicesAdminClient().prepareCreate(indexName);
// TODO: SYNONYMS need to be moved to core
/*
* if (SynonymsHelper.isSynonymsEnabled()) {
* indexRequestBuilder.setSettings(SynonymsHelper.
* createIndexSettings()); }
*/
CreateIndexResponse response = indexRequestBuilder.execute().actionGet();
log.info("Index: " + indexName + ", isAcknowledged: " + response.isAcknowledged());
}
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:17,代码来源:DefaultElasticsearchIndexHelper.java
示例15: checkForOrCreateIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入依赖的package包/类
/**
* 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);
}
}