diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java
index c448c9367668f..2574719aa61bb 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java
@@ -61,8 +61,15 @@ public IndicesOptions indicesOptions() {
return indicesOptions;
}
- public IndicesExistsRequest indicesOptions(IndicesOptions indicesOptions) {
- this.indicesOptions = indicesOptions;
+ public IndicesExistsRequest expandWilcardsOpen(boolean expandWildcardsOpen) {
+ this.indicesOptions = IndicesOptions.fromOptions(indicesOptions.ignoreUnavailable(), indicesOptions.allowNoIndices(),
+ expandWildcardsOpen, indicesOptions.expandWildcardsClosed());
+ return this;
+ }
+
+ public IndicesExistsRequest expandWilcardsClosed(boolean expandWildcardsClosed) {
+ this.indicesOptions = IndicesOptions.fromOptions(indicesOptions.ignoreUnavailable(), indicesOptions.allowNoIndices(),
+ indicesOptions.expandWildcardsOpen(), expandWildcardsClosed);
return this;
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequestBuilder.java
index 183648b5dd9e6..87da4627047ef 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequestBuilder.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequestBuilder.java
@@ -19,7 +19,6 @@
package org.elasticsearch.action.admin.indices.exists.indices;
-import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
@@ -35,12 +34,18 @@ public IndicesExistsRequestBuilder setIndices(String... indices) {
}
/**
- * Specifies what type of requested indices to ignore and wildcard indices expressions.
- *
- * For example indices that don't exist.
+ * Controls whether wildcard expressions will be expanded to existing open indices
*/
- public IndicesExistsRequestBuilder setIndicesOptions(IndicesOptions options) {
- request.indicesOptions(options);
+ public IndicesExistsRequestBuilder setExpandWildcardsOpen(boolean expandWildcardsOpen) {
+ request.expandWilcardsOpen(expandWildcardsOpen);
+ return this;
+ }
+
+ /**
+ * Controls whether wildcard expressions will be expanded to existing closed indices
+ */
+ public IndicesExistsRequestBuilder setExpandWildcardsClosed(boolean expandWildcardsClosed) {
+ request.expandWilcardsClosed(expandWildcardsClosed);
return this;
}
}
diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesExistsAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesExistsAction.java
index 520bca4e53f27..ed7e656aa0a39 100644
--- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesExistsAction.java
+++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesExistsAction.java
@@ -51,7 +51,9 @@ public RestIndicesExistsAction(Settings settings, RestController controller) {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(Strings.splitStringByCommaToArray(request.param("index")));
- indicesExistsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesExistsRequest.indicesOptions()));
+ IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, indicesExistsRequest.indicesOptions());
+ indicesExistsRequest.expandWilcardsOpen(indicesOptions.expandWildcardsOpen());
+ indicesExistsRequest.expandWilcardsClosed(indicesOptions.expandWildcardsClosed());
indicesExistsRequest.local(request.paramAsBoolean("local", indicesExistsRequest.local()));
return channel -> client.admin().indices().exists(indicesExistsRequest, new RestResponseListener(channel) {
@Override
diff --git a/core/src/test/java/org/elasticsearch/indices/exists/indices/IndicesExistsIT.java b/core/src/test/java/org/elasticsearch/indices/exists/indices/IndicesExistsIT.java
index 6052add7e3673..1f56e4cfc573c 100644
--- a/core/src/test/java/org/elasticsearch/indices/exists/indices/IndicesExistsIT.java
+++ b/core/src/test/java/org/elasticsearch/indices/exists/indices/IndicesExistsIT.java
@@ -19,7 +19,8 @@
package org.elasticsearch.indices.exists.indices;
-import org.elasticsearch.action.support.IndicesOptions;
+import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
+import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.test.ESIntegTestCase;
@@ -29,21 +30,33 @@
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_BLOCKS_READ;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_BLOCKS_WRITE;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_READ_ONLY;
+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
public class IndicesExistsIT extends ESIntegTestCase {
// Indices exists never throws IndexMissingException, the indices options control its behaviour (return true or false)
public void testIndicesExists() throws Exception {
- assertThat(client().admin().indices().prepareExists("foo").get().isExists(), equalTo(false));
- assertThat(client().admin().indices().prepareExists("foo").setIndicesOptions(IndicesOptions.lenientExpandOpen()).get().isExists(), equalTo(true));
- assertThat(client().admin().indices().prepareExists("foo*").get().isExists(), equalTo(false));
- assertThat(client().admin().indices().prepareExists("foo*").setIndicesOptions(IndicesOptions.fromOptions(false, true, true, false)).get().isExists(), equalTo(true));
- assertThat(client().admin().indices().prepareExists("_all").get().isExists(), equalTo(false));
+ 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));
diff --git a/docs/reference/migration/migrate_6_0/rest.asciidoc b/docs/reference/migration/migrate_6_0/rest.asciidoc
index 897b3a53e8596..e68682da9ed57 100644
--- a/docs/reference/migration/migrate_6_0/rest.asciidoc
+++ b/docs/reference/migration/migrate_6_0/rest.asciidoc
@@ -11,3 +11,9 @@ has been removed in Elasticsearch 6.0.0.
==== Analyze API changes
The deprecated request parameters and plain text in request body has been removed. Define parameters in request body.
+
+==== Indices exists API
+
+The `ignore_unavailable` and `allow_no_indices` options are no longer accepted
+as they could cause undesired results when their values differed from their
+defaults.
diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.exists.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.exists.json
index ebfd5cc3a7335..4ab053cd11873 100644
--- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.exists.json
+++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.exists.json
@@ -13,14 +13,6 @@
}
},
"params": {
- "ignore_unavailable": {
- "type" : "boolean",
- "description" : "Whether specified concrete indices should be ignored when unavailable (missing or closed)"
- },
- "allow_no_indices": {
- "type" : "boolean",
- "description" : "Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"
- },
"expand_wildcards": {
"type" : "enum",
"options" : ["open","closed","none","all"],