本文整理汇总了Java中org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse.isExists方法的典型用法代码示例。如果您正苦于以下问题:Java IndicesExistsResponse.isExists方法的具体用法?Java IndicesExistsResponse.isExists怎么用?Java IndicesExistsResponse.isExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse
的用法示例。
在下文中一共展示了IndicesExistsResponse.isExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeLoad
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
@Override
protected void beforeLoad(boolean reset) {
try {
IndicesExistsResponse res = esClient.prepareExists().get();
if (!res.isExists()) {
createIndex();
} else {
if (reset) {
deleteIndex();
createIndex();
}
}
bulkProcessor = createBulkProcessor();
} catch (Exception e) {
throw new IndexingException(e);
}
}
示例2: initIndexIfNotExists
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
/**
* Init index setting and mapping.
*
* @return true if a new index was created, false otherwise
*/
public boolean initIndexIfNotExists() throws IOException {
final IndicesExistsResponse existsResponse = esClient.admin().indices().prepareExists(INDEX).get();
if (existsResponse.isExists()) {
return false;
}
final String settings = Resources.toString(
getClass().getResource("/elasticsearch/product_settings.json"),
Charset.defaultCharset()
);
CreateIndexRequestBuilder createIndexRequestBuilder =
esClient
.admin()
.indices()
.prepareCreate(INDEX)
.setSettings(settings);
final String mapping = Resources.toString(
getClass().getResource("/elasticsearch/product_mappings.json"),
Charset.defaultCharset()
);
createIndexRequestBuilder = createIndexRequestBuilder.addMapping(TYPE, mapping);
return createIndexRequestBuilder.get().isShardsAcked();
}
示例3: init
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
@PostConfigured
public void init() throws IOException {
final IndicesExistsResponse response = client
.admin()
.indices()
.prepareExists("messages")
.get(TimeValue.timeValueMillis(1000));
if (!response.isExists()) {
// XContentBuilder mapping = jsonBuilder()
// .startObject("properties")
// .startObject("userId")
// .field("type", "string")
// .field("store", "yes")
// .endObject()
// .startObject("timestamp")
// .field("type", "date")
// .field("store", "yes")
// .endObject()
// .endObject();
client.admin().indices().prepareCreate("messages")
// .addMapping("message", mapping)
.get();
}
}
示例4: createIndex
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的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;
}
示例5: createIndexIfNotExists
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的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));
}
}
示例6: initIndex
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
public void initIndex(String indexName) {
if (indexMappings.containsKey(indexName)) {
return;
}
final IndicesExistsResponse res = elasticSearchService.getClient().admin().indices().prepareExists(indexName).execute().actionGet();
if (res.isExists()) {
//final DeleteIndexRequestBuilder delIdx = client.admin().indices().prepareDelete(indexName);
// delIdx.execute().actionGet();
new Throwable("WARNING: " + indexName + " already exists, this normally shouldn't happen ! This might happen if you have another instance of the LogAnalyzer running !").printStackTrace();
} else {
elasticSearchService.getClient().admin().indices().prepareCreate(indexName).get();
}
indexMappings.put(indexName, new HashSet<String>());
}
示例7: checkForOrCreateIndex
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的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);
}
}
示例8: prepareTest
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
@BeforeClass
public void prepareTest() throws Exception {
Config reference = ConfigFactory.load();
File conf_file = new File("target/test-classes/TwitterUserstreamElasticsearchIT.conf");
assert(conf_file.exists());
Config testResourceConfig = ConfigFactory.parseFileAnySyntax(conf_file, ConfigParseOptions.defaults().setAllowMissing(false));
Config typesafe = testResourceConfig.withFallback(reference).resolve();
testConfiguration = new ComponentConfigurator<>(TwitterUserstreamElasticsearchConfiguration.class).detectConfiguration(typesafe);
testClient = ElasticsearchClientManager.getInstance(testConfiguration.getElasticsearch()).client();
ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);
IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getElasticsearch().getIndex());
IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
if(indicesExistsResponse.isExists()) {
DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getElasticsearch().getIndex());
DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
assertTrue(deleteIndexResponse.isAcknowledged());
};
}
示例9: prepareTest
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
@BeforeClass
public void prepareTest() throws Exception {
Config reference = ConfigFactory.load();
File conf_file = new File("target/test-classes/HdfsElasticsearchIT.conf");
assert(conf_file.exists());
Config testResourceConfig = ConfigFactory.parseFileAnySyntax(conf_file, ConfigParseOptions.defaults().setAllowMissing(false));
Config typesafe = testResourceConfig.withFallback(reference).resolve();
testConfiguration = new ComponentConfigurator<>(HdfsElasticsearchConfiguration.class).detectConfiguration(typesafe);
testClient = ElasticsearchClientManager.getInstance(testConfiguration.getDestination()).client();
ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);
IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getDestination().getIndex());
IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
if(indicesExistsResponse.isExists()) {
DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getDestination().getIndex());
DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
assertTrue(deleteIndexResponse.isAcknowledged());
};
}
示例10: prepareTest
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
@BeforeClass
public void prepareTest() throws Exception {
Config reference = ConfigFactory.load();
File conf_file = new File("target/test-classes/TwitterHistoryElasticsearchIT.conf");
assert(conf_file.exists());
Config testResourceConfig = ConfigFactory.parseFileAnySyntax(conf_file, ConfigParseOptions.defaults().setAllowMissing(false));
Config typesafe = testResourceConfig.withFallback(reference).resolve();
testConfiguration = new ComponentConfigurator<>(TwitterHistoryElasticsearchConfiguration.class).detectConfiguration(typesafe);
testClient = ElasticsearchClientManager.getInstance(testConfiguration.getElasticsearch()).client();
ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);
IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getElasticsearch().getIndex());
IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
if(indicesExistsResponse.isExists()) {
DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getElasticsearch().getIndex());
DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
assertTrue(deleteIndexResponse.isAcknowledged());
};
}
示例11: deleteIndex
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
/**
* Deletes an index and block until deletion is complete.
*
* @param index The index to delete
* @param client The client which points to the Elasticsearch instance
* @throws InterruptedException if blocking thread is interrupted or index existence check failed
* @throws java.util.concurrent.ExecutionException if index existence check failed
* @throws IOException if deletion failed
*/
static void deleteIndex(String index, Client client)
throws InterruptedException, java.util.concurrent.ExecutionException, IOException {
IndicesAdminClient indices = client.admin().indices();
IndicesExistsResponse indicesExistsResponse =
indices.exists(new IndicesExistsRequest(index)).get();
if (indicesExistsResponse.isExists()) {
indices.prepareClose(index).get();
// delete index is an asynchronous request, neither refresh or upgrade
// delete all docs before starting tests. WaitForYellow() and delete directory are too slow,
// so block thread until it is done (make it synchronous!!!)
AtomicBoolean indexDeleted = new AtomicBoolean(false);
AtomicBoolean waitForIndexDeletion = new AtomicBoolean(true);
indices.delete(
Requests.deleteIndexRequest(index),
new DeleteActionListener(indexDeleted, waitForIndexDeletion));
while (waitForIndexDeletion.get()) {
Thread.sleep(100);
}
if (!indexDeleted.get()) {
throw new IOException("Failed to delete index " + index);
}
}
}
示例12: createMapping
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
/**
* Create a mapping over an index
*
* @param indexName
* @param mappingName
* @param mappingSource the data that has to be inserted in the mapping.
*/
public void createMapping(String indexName, String mappingName, ArrayList<XContentBuilder> mappingSource) {
IndicesExistsResponse existsResponse = this.client.admin().indices().prepareExists(indexName).execute()
.actionGet();
//If the index does not exists, it will be created without options
if (!existsResponse.isExists()) {
if (!createSingleIndex(indexName)) {
throw new ElasticsearchException("Failed to create " + indexName
+ " index.");
}
}
BulkRequestBuilder bulkRequest = this.client.prepareBulk();
for (int i = 0; i < mappingSource.size(); i++) {
int aux = i + 1;
IndexRequestBuilder res = this.client
.prepareIndex(indexName, mappingName, String.valueOf(aux)).setSource(mappingSource.get(i));
bulkRequest.add(res);
}
bulkRequest.execute();
}
示例13: setUpIndexAliases
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
private void setUpIndexAliases(IndexConfig indexConfig, ActorStateUpdate update) throws Exception {
String baseIndexName = indexConfig.indexName();
String fullIndexName = constructIndexName(indexConfig, update);
IndicesExistsResponse indicesExistsResponse = client.admin()
.indices()
.prepareExists(fullIndexName)
.execute().get();
if (!indicesExistsResponse.isExists()) {
client.admin()
.indices()
.prepareCreate(fullIndexName)
.execute().get();
client.admin()
.indices()
.prepareAliases()
.addAlias(fullIndexName, baseIndexName)
.execute().get();
}
}
示例14: initIndexes
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
public void initIndexes(String indexName, Class<?>[] classes) throws Exception {
// check if existing before
final ActionFuture<IndicesExistsResponse> indexExistFuture = esClient.getClient().admin().indices().exists(new IndicesExistsRequest(indexName));
IndicesExistsResponse response;
response = indexExistFuture.get();
if (!response.isExists()) {
// create the index and add the mapping
CreateIndexRequestBuilder createIndexRequestBuilder = esClient.getClient().admin().indices().prepareCreate(indexName);
for (Class<?> clazz : classes) {
System.out.println(mappingBuilder.getMapping(clazz));
createIndexRequestBuilder.addMapping(clazz.getSimpleName().toLowerCase(), mappingBuilder.getMapping(clazz));
}
final CreateIndexResponse createResponse = createIndexRequestBuilder.execute().actionGet();
if (!createResponse.isAcknowledged()) {
throw new Exception("Failed to create index <" + indexName + ">");
}
}
}
开发者ID:alien4cloud,项目名称:elasticsearch-mapping-parent,代码行数:21,代码来源:ElasticSearchInsertMappingTest.java
示例15: startUp
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入方法依赖的package包/类
@Override
protected void startUp() throws Exception {
IndicesAdminClient indices = esClient.admin().indices();
IndicesExistsResponse exists = get(indices.exists(
Requests.indicesExistsRequest(indexName)
));
if (!exists.isExists()) {
log.info("Creating index {}", indexName);
get(indices.create(Requests.createIndexRequest(indexName)));
get(indices.putMapping(Requests.putMappingRequest(indexName)
.type(EsTopic.TYPE_NAME).source(EsTopic.getMapping())
));
} else {
log.info("Index {} exists", indexName);
}
}