org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexExists.java    From sfs with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: ElasticToMongoProvider.java    From mongolastic with MIT License 6 votes vote down vote up
@Override
public long getCount() {
    long count = 0;
    IndicesAdminClient admin = elastic.getClient().admin().indices();
    IndicesExistsRequestBuilder builder = admin.prepareExists(config.getMisc().getDindex().getName());
    if (builder.execute().actionGet().isExists()) {
        SearchResponse countResponse = elastic.getClient().prepareSearch(config.getMisc().getDindex().getName())
                .setTypes(config.getMisc().getCtype().getName())
                .setSearchType(SearchType.QUERY_THEN_FETCH)
                .setSize(0)
                .execute().actionGet();
        count = countResponse.getHits().getTotalHits();
    } else {
        logger.info("Index/Type does not exist or does not contain the record");
        System.exit(-1);
    }

    logger.info("Elastic Index/Type count: " + count);
    return count;
}
 
Example #3
Source File: ClientFacade.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
private boolean indexesExist(List<Index> indexes) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("Determining index(es) '{}' existence ...", toString(indexes));
  }

  String[] indexNames = toIndexNames(indexes);
  IndicesExistsRequestBuilder indicesExistsRequest =
      client.admin().indices().prepareExists(indexNames);

  IndicesExistsResponse indicesExistsResponse;
  try {
    indicesExistsResponse = indicesExistsRequest.get();
  } catch (ElasticsearchException e) {
    LOG.error("", e);
    throw new IndexException(
        format("Error determining index(es) '%s' existence.", toString(indexes)));
  }

  boolean exists = indicesExistsResponse.isExists();
  if (LOG.isDebugEnabled()) {
    LOG.debug("Determined index(es) '{}' existence: {}.", toString(indexes), exists);
  }
  return exists;
}
 
Example #4
Source File: ModelsAction.java    From zentity with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the .zentity-models index exists, and if it doesn't, then create it.
 *
 * @param client The client that will communicate with Elasticsearch.
 * @throws ForbiddenException
 */
public static void ensureIndex(NodeClient client) throws ForbiddenException {
    try {
        IndicesExistsRequestBuilder request = client.admin().indices().prepareExists(INDEX_NAME);
        IndicesExistsResponse response = request.get();
        if (!response.isExists())
            SetupAction.createIndex(client);
    } catch (ElasticsearchSecurityException se) {
        throw new ForbiddenException("The .zentity-models index does not exist and you do not have the 'create_index' privilege. An authorized user must create the index by submitting: POST _zentity/_setup");
    }
}
 
Example #5
Source File: PluginClient.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
public boolean indexExists(final String index) {
    return execute(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            LOGGER.trace("Checking for existance of index '{}'", index);
            IndicesExistsRequestBuilder builder = client.admin().indices().prepareExists(index);
            IndicesExistsResponse response = builder.get();
            boolean exists = response.isExists();
            LOGGER.trace("Index '{}' exists? {}", index, exists);
            return exists;
        }
    });
}
 
Example #6
Source File: ElasticBulkService.java    From mongolastic with MIT License 5 votes vote down vote up
@Override
public void dropDataSet() {
    final String indexName = config.getMisc().getDindex().getAs();
    IndicesAdminClient admin = client.getClient().admin().indices();
    IndicesExistsRequestBuilder builder = admin.prepareExists(indexName);
    if (builder.execute().actionGet().isExists()) {
        DeleteIndexResponse delete = admin.delete(new DeleteIndexRequest(indexName)).actionGet();
        if (delete.isAcknowledged())
            logger.info(String.format("The current index %s was deleted.", indexName));
        else
            logger.info(String.format("The current index %s was not deleted.", indexName));
    }
}
 
Example #7
Source File: TestMongoToElastic.java    From mongolastic with MIT License 5 votes vote down vote up
public long getCount(ElasticConfiguration elastic, YamlConfiguration config) {
    IndicesAdminClient admin = elastic.getClient().admin().indices();
    IndicesExistsRequestBuilder builder = admin.prepareExists(config.getMisc().getDindex().getAs());
    assertThat(builder.execute().actionGet().isExists(), is(true));

    elastic.getClient().admin().indices().flush(new FlushRequest(config.getMisc().getDindex().getAs())).actionGet();

    SearchResponse response = elastic.getClient().prepareSearch(config.getMisc().getDindex().getAs())
            .setTypes(config.getMisc().getCtype().getAs())
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setSize(0)
            .execute().actionGet();
    long count = response.getHits().getTotalHits();
    return count;
}
 
Example #8
Source File: ElasticClient.java    From Stargraph with MIT License 4 votes vote down vote up
IndicesExistsRequestBuilder prepareExists() {
    return client.admin().indices().prepareExists(getIndexName());
}
 
Example #9
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public IndicesExistsRequestBuilder prepareExists(String... indices) {
    return new IndicesExistsRequestBuilder(this, IndicesExistsAction.INSTANCE, indices);
}
 
Example #10
Source File: ElasticsearchClusterRunner.java    From elasticsearch-cluster-runner with Apache License 2.0 4 votes vote down vote up
public boolean indexExists(final String index, final BuilderCallback<IndicesExistsRequestBuilder> builder) {
    final IndicesExistsResponse actionGet = builder.apply(client().admin().indices().prepareExists(index)).execute().actionGet();
    return actionGet.isExists();
}
 
Example #11
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Indices exists.
 */
IndicesExistsRequestBuilder prepareExists(String... indices);