本文整理汇总了Java中org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest类的典型用法代码示例。如果您正苦于以下问题:Java IndicesExistsRequest类的具体用法?Java IndicesExistsRequest怎么用?Java IndicesExistsRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IndicesExistsRequest类属于org.elasticsearch.action.admin.indices.exists.indices包,在下文中一共展示了IndicesExistsRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIndicesExists
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的package包/类
public void testIndicesExists() throws Exception {
assertFalse(client().admin().indices().prepareExists("foo").get().isExists());
assertFalse(client().admin().indices().prepareExists("foo*").get().isExists());
assertFalse(client().admin().indices().prepareExists("_all").get().isExists());
createIndex("foo", "foobar", "bar", "barbaz");
IndicesExistsRequestBuilder indicesExistsRequestBuilder = client().admin().indices().prepareExists("foo*")
.setExpandWildcardsOpen(false);
IndicesExistsRequest request = indicesExistsRequestBuilder.request();
//check that ignore unavailable and allow no indices are set to false. That is their only valid value as it can't be overridden
assertFalse(request.indicesOptions().ignoreUnavailable());
assertFalse(request.indicesOptions().allowNoIndices());
assertThat(indicesExistsRequestBuilder.get().isExists(), equalTo(false));
assertAcked(client().admin().indices().prepareClose("foobar").get());
assertThat(client().admin().indices().prepareExists("foo*").get().isExists(), equalTo(true));
assertThat(client().admin().indices().prepareExists("foo*").setExpandWildcardsOpen(false)
.setExpandWildcardsClosed(false).get().isExists(), equalTo(false));
assertThat(client().admin().indices().prepareExists("foobar").get().isExists(), equalTo(true));
assertThat(client().admin().indices().prepareExists("foob*").setExpandWildcardsClosed(false).get().isExists(), equalTo(false));
assertThat(client().admin().indices().prepareExists("bar*").get().isExists(), equalTo(true));
assertThat(client().admin().indices().prepareExists("bar").get().isExists(), equalTo(true));
assertThat(client().admin().indices().prepareExists("_all").get().isExists(), equalTo(true));
}
示例2: handleRequest
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的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);
}
}
});
}
示例3: createIndex
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的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;
}
示例4: checkForOrCreateIndex
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的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);
}
}
示例5: prepareTest
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的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());
};
}
示例6: prepareTest
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的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());
}
示例7: testSync
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的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());
}
示例8: prepareTest
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的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());
};
}
示例9: prepareTest
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的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());
};
}
示例10: deleteIndex
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的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);
}
}
}
示例11: execute
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的package包/类
public void execute(IndicesExistsRequest request, final ActionListener<IndicesExistsResponse> listener) {
logger.debug("indices exists request {}", request);
try {
RequestUriBuilder uriBuilder = new RequestUriBuilder(Strings.arrayToCommaDelimitedString(request.indices()));
uriBuilder.addQueryParameter("local", request.local());
uriBuilder.addIndicesOptions(request);
indicesAdminClient.getHttpClient().submit(HttpClientRequest.<ByteBuf>create(HttpMethod.HEAD, uriBuilder.toString()))
.flatMap(HANDLES_404)
.flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<IndicesExistsResponse>>() {
@Override
public Observable<IndicesExistsResponse> call(final HttpClientResponse<ByteBuf> response) {
return IndicesExistsResponse.parse(response.getStatus().code());
}
})
.single()
.subscribe(new ListenerCompleterObserver<>(listener));
} catch (Exception e) {
listener.onFailure(e);
}
}
示例12: parseIndices
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的package包/类
public static String[] parseIndices(AST_Search searchTree, Client client) throws CommandException {
String[] indices = Strings.EMPTY_ARRAY;
// 过滤不存在的index,不然查询会失败
// 如果所有指定的index都不存在,那么将在所有的index查询该条件
String[] originIndices = ((String) searchTree.getOption(Option.INDEX))
.split(",");
ArrayList<String> listIndices = new ArrayList<String>();
for (String index : originIndices) {
if (client.admin().indices()
.exists(new IndicesExistsRequest(index)).actionGet()
.isExists()) {
listIndices.add(index);
}
}
if (listIndices.size() > 0)
indices = listIndices.toArray(new String[listIndices.size()]);
else
throw new CommandException(String.format("%s index not exsit", searchTree.getOption(Option.INDEX)));
return indices;
}
示例13: setup
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的package包/类
public void setup() throws IOException, NoSuchFieldException, IllegalAccessException {
String key;
CreateIndexResponse ciResp;
Reflections reflections = new Reflections("org.apache.usergrid.chop.webapp.dao");
Set<Class<? extends Dao>> daoClasses = reflections.getSubTypesOf(Dao.class);
IndicesAdminClient client = elasticSearchClient.getClient().admin().indices();
for (Class<? extends Dao> daoClass : daoClasses) {
key = daoClass.getDeclaredField("DAO_INDEX_KEY").get(null).toString();
if (!client.exists(new IndicesExistsRequest(key)).actionGet().isExists()) {
ciResp = client.create(new CreateIndexRequest(key)).actionGet();
if (ciResp.isAcknowledged()) {
LOG.debug("Index for key {} didn't exist, now created", key);
} else {
LOG.debug("Could not create index for key: {}", key);
}
} else {
LOG.debug("Key {} already exists", key);
}
}
}
示例14: initIndexes
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; //导入依赖的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.IndicesExistsRequest; //导入依赖的package包/类
public void startup() throws Exception {
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
settings.put("node.name", "testnode");
settings.put("gateway.type", "none");
settings.put("path.data", "target/search-data");
settings.put("http.enabled", true);
settings.put("http.port", HTTP_PORT);
// settings.put("index.compound_format", false);
settings.put("transport.tcp.port", TRANSPORT_PORT);
_node = NodeBuilder.nodeBuilder().settings(settings).clusterName(CLUSTER_NAME).data(true).local(false).node();
try (Client client = _node.client()) {
IndicesAdminClient indicesAdmin = client.admin().indices();
if (!indicesAdmin.exists(new IndicesExistsRequest(INDEX_NAME)).actionGet().isExists()) {
indicesAdmin.create(new CreateIndexRequest(INDEX_NAME)).actionGet();
}
}
System.out.println("--- ElasticSearchTestServer started ---");
}