Search in sources :

Example 1 with IndicesExistsRequestBuilder

use of org.opensearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder in project OpenSearch by opensearch-project.

the class IndicesExistsIT method testIndicesExists.

// Indices exists never throws IndexMissingException, the indices options control its behaviour (return true or false)
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));
}
Also used : IndicesExistsRequestBuilder(org.opensearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder) IndicesExistsRequest(org.opensearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Aggregations

IndicesExistsRequest (org.opensearch.action.admin.indices.exists.indices.IndicesExistsRequest)1 IndicesExistsRequestBuilder (org.opensearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder)1