本文整理汇总了Java中org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse类的典型用法代码示例。如果您正苦于以下问题:Java IndicesExistsResponse类的具体用法?Java IndicesExistsResponse怎么用?Java IndicesExistsResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IndicesExistsResponse类属于org.elasticsearch.action.admin.indices.exists.indices包,在下文中一共展示了IndicesExistsResponse类的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: testIndexExists
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入依赖的package包/类
@Test
public void testIndexExists() {
//Test data
final String indexName = "index";
final AdminClient adminClient = createMock(AdminClient.class);
final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
final IndicesExistsRequestBuilder indicesExistsRequestBuilder = createMock(IndicesExistsRequestBuilder.class);
final IndicesExistsResponse indicesExistsResponse = createMock(IndicesExistsResponse.class);
final boolean exists = new Random().nextBoolean();
//Reset
resetAll();
//Expectations
expect(esClient.admin()).andReturn(adminClient);
expect(adminClient.indices()).andReturn(indicesAdminClient);
expect(indicesAdminClient.prepareExists(indexName)).andReturn(indicesExistsRequestBuilder);
expect(indicesExistsRequestBuilder.get()).andReturn(indicesExistsResponse);
expect(indicesExistsResponse.isExists()).andReturn(exists);
//Replay
replayAll();
//Run test scenario
final boolean result = elasticsearchClientWrapper.indexExists(indexName);
//Verify
verifyAll();
assertEquals(exists, result);
}
示例5: handleRequest
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(Strings.splitStringByCommaToArray(request.param("index")));
indicesExistsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesExistsRequest.indicesOptions()));
indicesExistsRequest.local(request.paramAsBoolean("local", indicesExistsRequest.local()));
client.admin().indices().exists(indicesExistsRequest, new RestResponseListener<IndicesExistsResponse>(channel) {
@Override
public RestResponse buildResponse(IndicesExistsResponse response) {
if (response.isExists()) {
return new BytesRestResponse(OK);
} else {
return new BytesRestResponse(NOT_FOUND);
}
}
});
}
示例6: 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;
}
示例7: 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));
}
}
示例8: call
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入依赖的package包/类
@Override
public Observable<Boolean> call(String index) {
Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
IndicesExistsRequestBuilder request = elasticsearch.get().admin().indices().prepareExists(index);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Request %s", Jsonify.toString(request)));
}
return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
.map(Optional::get)
.doOnNext(indicesExistsResponse -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Response %s", Jsonify.toString(indicesExistsResponse)));
}
})
.map(IndicesExistsResponse::isExists);
}
示例9: 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>());
}
示例10: 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);
}
}
示例11: checkAuditIndex
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入依赖的package包/类
private void checkAuditIndex() {
client.admin().indices().prepareExists(auditIndexName).execute(new ActionListener<IndicesExistsResponse>() {
@Override
public void onResponse(final IndicesExistsResponse response) {
if (response.isExists()) {
if (logger.isDebugEnabled()) {
logger.debug("{} index exists already.", auditIndexName);
}
} else {
createAuditIndex();
}
}
@Override
public void onFailure(final Throwable e) {
logger.error("The state of {} index is invalid.", e, auditIndexName);
}
});
}
示例12: 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());
};
}
示例13: 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/MongoElasticsearchSyncIT.conf");
assert(conf_file.exists());
Config testResourceConfig = ConfigFactory.parseFileAnySyntax(conf_file, ConfigParseOptions.defaults().setAllowMissing(false));
Config typesafe = testResourceConfig.withFallback(reference).resolve();
testConfiguration = new ComponentConfigurator<>(MongoElasticsearchSyncConfiguration.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();
assertFalse(indicesExistsResponse.isExists());
}
示例14: testSync
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; //导入依赖的package包/类
@Test
public void testSync() throws Exception {
MongoElasticsearchSync sync = new MongoElasticsearchSync(testConfiguration);
sync.run();
IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getDestination().getIndex());
IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
assertTrue(indicesExistsResponse.isExists());
// assert lines in file
SearchRequestBuilder countRequest = testClient
.prepareSearch(testConfiguration.getDestination().getIndex())
.setTypes(testConfiguration.getDestination().getType());
SearchResponse countResponse = countRequest.execute().actionGet();
assertEquals(89, (int)countResponse.getHits().getTotalHits());
}
示例15: 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());
};
}