From 75cedca0dab933bb6d1679fbddea2d09122d13c9 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 2 Oct 2015 17:27:10 +0200 Subject: Remove search exists api Closes #13682 Closes #13911 --- .../org/elasticsearch/action/ActionModule.java | 3 - .../elasticsearch/action/exists/ExistsAction.java | 43 ---- .../elasticsearch/action/exists/ExistsRequest.java | 235 --------------------- .../action/exists/ExistsRequestBuilder.java | 119 ----------- .../action/exists/ExistsResponse.java | 61 ------ .../action/exists/ShardExistsRequest.java | 122 ----------- .../action/exists/ShardExistsResponse.java | 56 ----- .../action/exists/TransportExistsAction.java | 229 -------------------- .../elasticsearch/action/exists/package-info.java | 23 -- .../main/java/org/elasticsearch/client/Client.java | 26 --- .../java/org/elasticsearch/client/Requests.java | 13 -- .../client/support/AbstractClient.java | 19 -- .../rest/action/exists/RestExistsAction.java | 84 -------- .../rest/action/search/RestSearchAction.java | 9 - 14 files changed, 1042 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/action/exists/ExistsAction.java delete mode 100644 core/src/main/java/org/elasticsearch/action/exists/ExistsRequest.java delete mode 100644 core/src/main/java/org/elasticsearch/action/exists/ExistsRequestBuilder.java delete mode 100644 core/src/main/java/org/elasticsearch/action/exists/ExistsResponse.java delete mode 100644 core/src/main/java/org/elasticsearch/action/exists/ShardExistsRequest.java delete mode 100644 core/src/main/java/org/elasticsearch/action/exists/ShardExistsResponse.java delete mode 100644 core/src/main/java/org/elasticsearch/action/exists/TransportExistsAction.java delete mode 100644 core/src/main/java/org/elasticsearch/action/exists/package-info.java delete mode 100644 core/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java (limited to 'core/src/main/java/org/elasticsearch') diff --git a/core/src/main/java/org/elasticsearch/action/ActionModule.java b/core/src/main/java/org/elasticsearch/action/ActionModule.java index 5d215fd8bf..88ccb80971 100644 --- a/core/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/core/src/main/java/org/elasticsearch/action/ActionModule.java @@ -134,8 +134,6 @@ import org.elasticsearch.action.bulk.TransportBulkAction; import org.elasticsearch.action.bulk.TransportShardBulkAction; import org.elasticsearch.action.delete.DeleteAction; import org.elasticsearch.action.delete.TransportDeleteAction; -import org.elasticsearch.action.exists.ExistsAction; -import org.elasticsearch.action.exists.TransportExistsAction; import org.elasticsearch.action.explain.ExplainAction; import org.elasticsearch.action.explain.TransportExplainAction; import org.elasticsearch.action.fieldstats.FieldStatsAction; @@ -314,7 +312,6 @@ public class ActionModule extends AbstractModule { registerAction(MultiTermVectorsAction.INSTANCE, TransportMultiTermVectorsAction.class, TransportShardMultiTermsVectorAction.class); registerAction(DeleteAction.INSTANCE, TransportDeleteAction.class); - registerAction(ExistsAction.INSTANCE, TransportExistsAction.class); registerAction(SuggestAction.INSTANCE, TransportSuggestAction.class); registerAction(UpdateAction.INSTANCE, TransportUpdateAction.class); registerAction(MultiGetAction.INSTANCE, TransportMultiGetAction.class, diff --git a/core/src/main/java/org/elasticsearch/action/exists/ExistsAction.java b/core/src/main/java/org/elasticsearch/action/exists/ExistsAction.java deleted file mode 100644 index d4463aea0d..0000000000 --- a/core/src/main/java/org/elasticsearch/action/exists/ExistsAction.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.action.exists; - - -import org.elasticsearch.action.Action; -import org.elasticsearch.client.ElasticsearchClient; - -public class ExistsAction extends Action { - - public static final ExistsAction INSTANCE = new ExistsAction(); - public static final String NAME = "indices:data/read/exists"; - - private ExistsAction() { - super(NAME); - } - - @Override - public ExistsResponse newResponse() { - return new ExistsResponse(); - } - - @Override - public ExistsRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new ExistsRequestBuilder(client, this); - } -} diff --git a/core/src/main/java/org/elasticsearch/action/exists/ExistsRequest.java b/core/src/main/java/org/elasticsearch/action/exists/ExistsRequest.java deleted file mode 100644 index 0000676b3c..0000000000 --- a/core/src/main/java/org/elasticsearch/action/exists/ExistsRequest.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.action.exists; - -import org.elasticsearch.ElasticsearchGenerationException; -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.support.QuerySourceBuilder; -import org.elasticsearch.action.support.broadcast.BroadcastRequest; -import org.elasticsearch.client.Requests; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentHelper; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Map; - -public class ExistsRequest extends BroadcastRequest { - - public static final float DEFAULT_MIN_SCORE = -1f; - private float minScore = DEFAULT_MIN_SCORE; - - @Nullable - protected String routing; - - @Nullable - private String preference; - - private BytesReference source; - - private String[] types = Strings.EMPTY_ARRAY; - - long nowInMillis; - - public ExistsRequest() { - } - - /** - * Constructs a new exists request against the provided indices. No indices provided means it will - * run against all indices. - */ - public ExistsRequest(String... indices) { - super(indices); - } - - - @Override - public ActionRequestValidationException validate() { - ActionRequestValidationException validationException = super.validate(); - return validationException; - } - - /** - * The minimum score of the documents to include in the count. - */ - public float minScore() { - return minScore; - } - - /** - * The minimum score of the documents to include in the count. Defaults to -1 which means all - * documents will be considered. - */ - public ExistsRequest minScore(float minScore) { - this.minScore = minScore; - return this; - } - - /** - * A comma separated list of routing values to control the shards the search will be executed on. - */ - public String routing() { - return this.routing; - } - - /** - * A comma separated list of routing values to control the shards the search will be executed on. - */ - public ExistsRequest routing(String routing) { - this.routing = routing; - return this; - } - - /** - * The routing values to control the shards that the search will be executed on. - */ - public ExistsRequest routing(String... routings) { - this.routing = Strings.arrayToCommaDelimitedString(routings); - return this; - } - - /** - * Routing preference for executing the search on shards - */ - public ExistsRequest preference(String preference) { - this.preference = preference; - return this; - } - - public String preference() { - return this.preference; - } - - /** - * The source to execute. - */ - public BytesReference source() { - return source; - } - - /** - * The source to execute. - */ - public ExistsRequest source(QuerySourceBuilder sourceBuilder) { - this.source = sourceBuilder.buildAsBytes(Requests.CONTENT_TYPE); - return this; - } - - /** - * The source to execute in the form of a map. - */ - public ExistsRequest source(Map querySource) { - try { - XContentBuilder builder = XContentFactory.contentBuilder(Requests.CONTENT_TYPE); - builder.map(querySource); - return source(builder); - } catch (IOException e) { - throw new ElasticsearchGenerationException("Failed to generate [" + querySource + "]", e); - } - } - - public ExistsRequest source(XContentBuilder builder) { - this.source = builder.bytes(); - return this; - } - - /** - * The source to execute. It is preferable to use either {@link #source(byte[])} - * or {@link #source(QuerySourceBuilder)}. - */ - public ExistsRequest source(String querySource) { - this.source = new BytesArray(querySource); - return this; - } - - /** - * The source to execute. - */ - public ExistsRequest source(byte[] querySource) { - return source(querySource, 0, querySource.length); - } - - /** - * The source to execute. - */ - public ExistsRequest source(byte[] querySource, int offset, int length) { - return source(new BytesArray(querySource, offset, length)); - } - - public ExistsRequest source(BytesReference querySource) { - this.source = querySource; - return this; - } - - /** - * The types of documents the query will run against. Defaults to all types. - */ - public String[] types() { - return this.types; - } - - /** - * The types of documents the query will run against. Defaults to all types. - */ - public ExistsRequest types(String... types) { - this.types = types; - return this; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - minScore = in.readFloat(); - routing = in.readOptionalString(); - preference = in.readOptionalString(); - source = in.readBytesReference(); - types = in.readStringArray(); - - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeFloat(minScore); - out.writeOptionalString(routing); - out.writeOptionalString(preference); - out.writeBytesReference(source); - out.writeStringArray(types); - - } - - @Override - public String toString() { - String sSource = "_na_"; - try { - sSource = XContentHelper.convertToJson(source, false); - } catch (Exception e) { - // ignore - } - return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", source[" + sSource + "]"; - } -} diff --git a/core/src/main/java/org/elasticsearch/action/exists/ExistsRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/exists/ExistsRequestBuilder.java deleted file mode 100644 index c7ef5a10ce..0000000000 --- a/core/src/main/java/org/elasticsearch/action/exists/ExistsRequestBuilder.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.action.exists; - -import org.elasticsearch.action.support.QuerySourceBuilder; -import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; -import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.index.query.QueryBuilder; - -public class ExistsRequestBuilder extends BroadcastOperationRequestBuilder { - - private QuerySourceBuilder sourceBuilder; - - public ExistsRequestBuilder(ElasticsearchClient client, ExistsAction action) { - super(client, action, new ExistsRequest()); - } - - /** - * The types of documents the query will run against. Defaults to all types. - */ - public ExistsRequestBuilder setTypes(String... types) { - request.types(types); - return this; - } - - /** - * A comma separated list of routing values to control the shards the search will be executed on. - */ - public ExistsRequestBuilder setRouting(String routing) { - request.routing(routing); - return this; - } - - /** - * Sets the preference to execute the search. Defaults to randomize across shards. Can be set to - * _local to prefer local shards, _primary to execute only on primary shards, - * _shards:x,y to operate on shards x & y, or a custom value, which guarantees that the same order - * will be used across different requests. - */ - public ExistsRequestBuilder setPreference(String preference) { - request.preference(preference); - return this; - } - - /** - * The routing values to control the shards that the search will be executed on. - */ - public ExistsRequestBuilder setRouting(String... routing) { - request.routing(routing); - return this; - } - - /** - * The query source to execute. - * - * @see org.elasticsearch.index.query.QueryBuilders - */ - public ExistsRequestBuilder setQuery(QueryBuilder queryBuilder) { - sourceBuilder().setQuery(queryBuilder); - return this; - } - - /** - * The query binary to execute - */ - public ExistsRequestBuilder setQuery(BytesReference queryBinary) { - sourceBuilder().setQuery(queryBinary); - return this; - } - - /** - * The source to execute. - */ - public ExistsRequestBuilder setSource(BytesReference source) { - request().source(source); - return this; - } - - /** - * The query source to execute. - */ - public ExistsRequestBuilder setSource(byte[] querySource) { - request.source(querySource); - return this; - } - - @Override - protected ExistsRequest beforeExecute(ExistsRequest request) { - if (sourceBuilder != null) { - request.source(sourceBuilder); - } - return request; - } - - private QuerySourceBuilder sourceBuilder() { - if (sourceBuilder == null) { - sourceBuilder = new QuerySourceBuilder(); - } - return sourceBuilder; - } - -} diff --git a/core/src/main/java/org/elasticsearch/action/exists/ExistsResponse.java b/core/src/main/java/org/elasticsearch/action/exists/ExistsResponse.java deleted file mode 100644 index f271dc65f7..0000000000 --- a/core/src/main/java/org/elasticsearch/action/exists/ExistsResponse.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.action.exists; - -import org.elasticsearch.action.ShardOperationFailedException; -import org.elasticsearch.action.support.broadcast.BroadcastResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; - -import java.io.IOException; -import java.util.List; - -public class ExistsResponse extends BroadcastResponse { - - private boolean exists = false; - - ExistsResponse() { - - } - - ExistsResponse(boolean exists, int totalShards, int successfulShards, int failedShards, List shardFailures) { - super(totalShards, successfulShards, failedShards, shardFailures); - this.exists = exists; - } - - /** - * Whether the documents matching the query provided exists - */ - public boolean exists() { - return exists; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - exists = in.readBoolean(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeBoolean(exists); - } -} diff --git a/core/src/main/java/org/elasticsearch/action/exists/ShardExistsRequest.java b/core/src/main/java/org/elasticsearch/action/exists/ShardExistsRequest.java deleted file mode 100644 index d57b1d9901..0000000000 --- a/core/src/main/java/org/elasticsearch/action/exists/ShardExistsRequest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.action.exists; - -import org.elasticsearch.action.support.broadcast.BroadcastShardRequest; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.index.shard.ShardId; - -import java.io.IOException; - -public class ShardExistsRequest extends BroadcastShardRequest { - - private float minScore; - - private BytesReference querySource; - - private String[] types = Strings.EMPTY_ARRAY; - - private long nowInMillis; - - @Nullable - private String[] filteringAliases; - - public ShardExistsRequest() { - } - - ShardExistsRequest(ShardId shardId, @Nullable String[] filteringAliases, ExistsRequest request) { - super(shardId, request); - this.minScore = request.minScore(); - this.querySource = request.source(); - this.types = request.types(); - this.filteringAliases = filteringAliases; - this.nowInMillis = request.nowInMillis; - } - - public float minScore() { - return minScore; - } - - public BytesReference querySource() { - return querySource; - } - - public String[] types() { - return this.types; - } - - public String[] filteringAliases() { - return filteringAliases; - } - - public long nowInMillis() { - return this.nowInMillis; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - minScore = in.readFloat(); - - querySource = in.readBytesReference(); - - int typesSize = in.readVInt(); - if (typesSize > 0) { - types = new String[typesSize]; - for (int i = 0; i < typesSize; i++) { - types[i] = in.readString(); - } - } - int aliasesSize = in.readVInt(); - if (aliasesSize > 0) { - filteringAliases = new String[aliasesSize]; - for (int i = 0; i < aliasesSize; i++) { - filteringAliases[i] = in.readString(); - } - } - nowInMillis = in.readVLong(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeFloat(minScore); - - out.writeBytesReference(querySource); - - out.writeVInt(types.length); - for (String type : types) { - out.writeString(type); - } - if (filteringAliases != null) { - out.writeVInt(filteringAliases.length); - for (String alias : filteringAliases) { - out.writeString(alias); - } - } else { - out.writeVInt(0); - } - out.writeVLong(nowInMillis); - } -} diff --git a/core/src/main/java/org/elasticsearch/action/exists/ShardExistsResponse.java b/core/src/main/java/org/elasticsearch/action/exists/ShardExistsResponse.java deleted file mode 100644 index 25f813ee42..0000000000 --- a/core/src/main/java/org/elasticsearch/action/exists/ShardExistsResponse.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.action.exists; - -import org.elasticsearch.action.support.broadcast.BroadcastShardResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.index.shard.ShardId; - -import java.io.IOException; - -class ShardExistsResponse extends BroadcastShardResponse { - - private boolean exists; - - ShardExistsResponse() { - } - - ShardExistsResponse(ShardId shardId, boolean exists) { - super(shardId); - this.exists = exists; - } - - public boolean exists() { - return this.exists; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - exists = in.readBoolean(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeBoolean(exists); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/action/exists/TransportExistsAction.java b/core/src/main/java/org/elasticsearch/action/exists/TransportExistsAction.java deleted file mode 100644 index 46f998fc6a..0000000000 --- a/core/src/main/java/org/elasticsearch/action/exists/TransportExistsAction.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.action.exists; - - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.ShardOperationFailedException; -import org.elasticsearch.action.support.ActionFilters; -import org.elasticsearch.action.support.DefaultShardOperationFailedException; -import org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException; -import org.elasticsearch.action.support.broadcast.TransportBroadcastAction; -import org.elasticsearch.cache.recycler.PageCacheRecycler; -import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.block.ClusterBlockException; -import org.elasticsearch.cluster.block.ClusterBlockLevel; -import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.cluster.routing.GroupShardsIterator; -import org.elasticsearch.cluster.routing.ShardIterator; -import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.lucene.Lucene; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.BigArrays; -import org.elasticsearch.index.IndexService; -import org.elasticsearch.index.query.QueryShardContext; -import org.elasticsearch.index.shard.IndexShard; -import org.elasticsearch.indices.IndicesService; -import org.elasticsearch.script.ScriptService; -import org.elasticsearch.search.SearchService; -import org.elasticsearch.search.SearchShardTarget; -import org.elasticsearch.search.internal.DefaultSearchContext; -import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.search.internal.ShardSearchLocalRequest; -import org.elasticsearch.search.query.QueryPhaseExecutionException; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReferenceArray; - -import static org.elasticsearch.action.exists.ExistsRequest.DEFAULT_MIN_SCORE; - -public class TransportExistsAction extends TransportBroadcastAction { - - private final IndicesService indicesService; - private final ScriptService scriptService; - private final PageCacheRecycler pageCacheRecycler; - private final BigArrays bigArrays; - - @Inject - public TransportExistsAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, - IndicesService indicesService, ScriptService scriptService, - PageCacheRecycler pageCacheRecycler, BigArrays bigArrays, ActionFilters actionFilters, - IndexNameExpressionResolver indexNameExpressionResolver) { - super(settings, ExistsAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver, - ExistsRequest::new, ShardExistsRequest::new, ThreadPool.Names.SEARCH); - this.indicesService = indicesService; - this.scriptService = scriptService; - this.pageCacheRecycler = pageCacheRecycler; - this.bigArrays = bigArrays; - } - - @Override - protected void doExecute(ExistsRequest request, ActionListener listener) { - request.nowInMillis = System.currentTimeMillis(); - new ExistsAsyncBroadcastAction(request, listener).start(); - } - - @Override - protected ShardExistsRequest newShardRequest(int numShards, ShardRouting shard, ExistsRequest request) { - String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterService.state(), shard.index(), request.indices()); - return new ShardExistsRequest(shard.shardId(), filteringAliases, request); - } - - @Override - protected ShardExistsResponse newShardResponse() { - return new ShardExistsResponse(); - } - - @Override - protected GroupShardsIterator shards(ClusterState clusterState, ExistsRequest request, String[] concreteIndices) { - Map> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, request.routing(), request.indices()); - return clusterService.operationRouting().searchShards(clusterState, concreteIndices, routingMap, request.preference()); - } - - @Override - protected ClusterBlockException checkGlobalBlock(ClusterState state, ExistsRequest request) { - return state.blocks().globalBlockedException(ClusterBlockLevel.READ); - } - - @Override - protected ClusterBlockException checkRequestBlock(ClusterState state, ExistsRequest countRequest, String[] concreteIndices) { - return state.blocks().indicesBlockedException(ClusterBlockLevel.READ, concreteIndices); - } - - @Override - protected ExistsResponse newResponse(ExistsRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) { - int successfulShards = 0; - int failedShards = 0; - boolean exists = false; - List shardFailures = null; - - // if docs do exist, the last response will have exists = true (since we early terminate the shard requests) - for (int i = shardsResponses.length() - 1; i >= 0 ; i--) { - Object shardResponse = shardsResponses.get(i); - if (shardResponse == null) { - // simply ignore non active shards - } else if (shardResponse instanceof BroadcastShardOperationFailedException) { - failedShards++; - if (shardFailures == null) { - shardFailures = new ArrayList<>(); - } - shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse)); - } else { - successfulShards++; - if ((exists = ((ShardExistsResponse) shardResponse).exists())) { - successfulShards = shardsResponses.length() - failedShards; - break; - } - } - } - return new ExistsResponse(exists, shardsResponses.length(), successfulShards, failedShards, shardFailures); - } - - @Override - protected ShardExistsResponse shardOperation(ShardExistsRequest request) { - IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex()); - IndexShard indexShard = indexService.getShard(request.shardId().id()); - - SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().id(), request.shardId().getIndex(), request.shardId().id()); - SearchContext context = new DefaultSearchContext(0, - new ShardSearchLocalRequest(request.types(), request.nowInMillis(), request.filteringAliases()), - shardTarget, indexShard.acquireSearcher("exists"), indexService, indexShard, - scriptService, pageCacheRecycler, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, - SearchService.NO_TIMEOUT - ); - SearchContext.setCurrent(context); - - try { - if (request.minScore() != DEFAULT_MIN_SCORE) { - context.minimumScore(request.minScore()); - } - BytesReference source = request.querySource(); - if (source != null && source.length() > 0) { - try { - QueryShardContext.setTypes(request.types()); - context.parsedQuery(indexService.queryParserService().parseQuery(source)); - } finally { - QueryShardContext.removeTypes(); - } - } - context.preProcess(); - try { - boolean exists; - try { - exists = Lucene.exists(context.searcher(), context.query()); - } finally { - context.clearReleasables(SearchContext.Lifetime.COLLECTION); - } - return new ShardExistsResponse(request.shardId(), exists); - } catch (Exception e) { - throw new QueryPhaseExecutionException(context, "failed to execute exists", e); - } - } finally { - // this will also release the index searcher - context.close(); - SearchContext.removeCurrent(); - } - } - - /** - * An async broadcast action that early terminates shard request - * upon any shard response reporting matched doc existence - */ - final private class ExistsAsyncBroadcastAction extends AsyncBroadcastAction { - - final AtomicBoolean processed = new AtomicBoolean(false); - - ExistsAsyncBroadcastAction(ExistsRequest request, ActionListener listener) { - super(request, listener); - } - - @Override - protected void onOperation(ShardRouting shard, int shardIndex, ShardExistsResponse response) { - super.onOperation(shard, shardIndex, response); - if (response.exists()) { - finishHim(); - } - } - - @Override - protected void performOperation(final ShardIterator shardIt, final ShardRouting shard, final int shardIndex) { - if (processed.get()) { - return; - } - super.performOperation(shardIt, shard, shardIndex); - } - - @Override - protected void finishHim() { - if (processed.compareAndSet(false, true)) { - super.finishHim(); - } - } - } -} diff --git a/core/src/main/java/org/elasticsearch/action/exists/package-info.java b/core/src/main/java/org/elasticsearch/action/exists/package-info.java deleted file mode 100644 index 1b92118788..0000000000 --- a/core/src/main/java/org/elasticsearch/action/exists/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * Exists action. - */ -package org.elasticsearch.action.exists; \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/client/Client.java b/core/src/main/java/org/elasticsearch/client/Client.java index 67e60f41ea..a396e183bb 100644 --- a/core/src/main/java/org/elasticsearch/client/Client.java +++ b/core/src/main/java/org/elasticsearch/client/Client.java @@ -27,9 +27,6 @@ import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteRequestBuilder; import org.elasticsearch.action.delete.DeleteResponse; -import org.elasticsearch.action.exists.ExistsRequest; -import org.elasticsearch.action.exists.ExistsRequestBuilder; -import org.elasticsearch.action.exists.ExistsResponse; import org.elasticsearch.action.explain.ExplainRequest; import org.elasticsearch.action.explain.ExplainRequestBuilder; import org.elasticsearch.action.explain.ExplainResponse; @@ -334,29 +331,6 @@ public interface Client extends ElasticsearchClient, Releasable { */ MultiGetRequestBuilder prepareMultiGet(); - /** - * Checks existence of any documents matching a specific query. - * - * @param request The exists request - * @return The result future - * @see Requests#existsRequest(String...) - */ - ActionFuture exists(ExistsRequest request); - - /** - * Checks existence of any documents matching a specific query. - * - * @param request The exists request - * @param listener A listener to be notified of the result - * @see Requests#existsRequest(String...) - */ - void exists(ExistsRequest request, ActionListener listener); - - /** - * Checks existence of any documents matching a specific query. - */ - ExistsRequestBuilder prepareExists(String... indices); - /** * Suggestion matching a specific phrase. * diff --git a/core/src/main/java/org/elasticsearch/client/Requests.java b/core/src/main/java/org/elasticsearch/client/Requests.java index b99c99a509..7f0decaba5 100644 --- a/core/src/main/java/org/elasticsearch/client/Requests.java +++ b/core/src/main/java/org/elasticsearch/client/Requests.java @@ -53,7 +53,6 @@ import org.elasticsearch.action.admin.indices.shards.IndicesShardStoresRequest; import org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.delete.DeleteRequest; -import org.elasticsearch.action.exists.ExistsRequest; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.search.SearchRequest; @@ -123,18 +122,6 @@ public class Requests { return new GetRequest(index); } - /** - * Creates a exists request which checks if any of the hits matched against a query exists. Note, the query itself must be set - * either using the JSON source of the query, or using a {@link org.elasticsearch.index.query.QueryBuilder} (using {@link org.elasticsearch.index.query.QueryBuilders}). - * - * @param indices The indices to count matched documents against a query. Use null or _all to execute against all indices - * @return The exists request - * @see org.elasticsearch.client.Client#exists(org.elasticsearch.action.exists.ExistsRequest) - */ - public static ExistsRequest existsRequest(String... indices) { - return new ExistsRequest(indices); - } - /** * Creates a suggest request for getting suggestions from provided indices. * The suggest query has to be set using the JSON source using {@link org.elasticsearch.action.suggest.SuggestRequest#suggest(org.elasticsearch.common.bytes.BytesReference)}. diff --git a/core/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/core/src/main/java/org/elasticsearch/client/support/AbstractClient.java index 43051a9e17..fab45ff30c 100644 --- a/core/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/core/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -232,10 +232,6 @@ import org.elasticsearch.action.delete.DeleteAction; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteRequestBuilder; import org.elasticsearch.action.delete.DeleteResponse; -import org.elasticsearch.action.exists.ExistsAction; -import org.elasticsearch.action.exists.ExistsRequest; -import org.elasticsearch.action.exists.ExistsRequestBuilder; -import org.elasticsearch.action.exists.ExistsResponse; import org.elasticsearch.action.explain.ExplainAction; import org.elasticsearch.action.explain.ExplainRequest; import org.elasticsearch.action.explain.ExplainRequestBuilder; @@ -601,21 +597,6 @@ public abstract class AbstractClient extends AbstractComponent implements Client return new MultiSearchRequestBuilder(this, MultiSearchAction.INSTANCE); } - @Override - public ActionFuture exists(final ExistsRequest request) { - return execute(ExistsAction.INSTANCE, request); - } - - @Override - public void exists(final ExistsRequest request, final ActionListener listener) { - execute(ExistsAction.INSTANCE, request, listener); - } - - @Override - public ExistsRequestBuilder prepareExists(String... indices) { - return new ExistsRequestBuilder(this, ExistsAction.INSTANCE).setIndices(indices); - } - @Override public ActionFuture suggest(final SuggestRequest request) { return execute(SuggestAction.INSTANCE, request); diff --git a/core/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java b/core/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java deleted file mode 100644 index 04f548b787..0000000000 --- a/core/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.rest.action.exists; - -import org.elasticsearch.action.exists.ExistsRequest; -import org.elasticsearch.action.exists.ExistsResponse; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.QuerySourceBuilder; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.RestResponse; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestBuilderListener; - -import static org.elasticsearch.action.exists.ExistsRequest.DEFAULT_MIN_SCORE; -import static org.elasticsearch.rest.RestStatus.NOT_FOUND; -import static org.elasticsearch.rest.RestStatus.OK; - -/** - * Action for /_search/exists endpoint - */ -public class RestExistsAction extends BaseRestHandler { - - public RestExistsAction(Settings settings, RestController controller, Client client) { - super(settings, controller, client); - } - - @Override - public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { - final ExistsRequest existsRequest = new ExistsRequest(Strings.splitStringByCommaToArray(request.param("index"))); - existsRequest.indicesOptions(IndicesOptions.fromRequest(request, existsRequest.indicesOptions())); - if (RestActions.hasBodyContent(request)) { - existsRequest.source(RestActions.getRestContent(request)); - } else { - QueryBuilder queryBuilder = RestActions.urlParamsToQueryBuilder(request); - if (queryBuilder != null) { - QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder(); - querySourceBuilder.setQuery(queryBuilder); - existsRequest.source(querySourceBuilder.buildAsBytes()); - } - } - existsRequest.routing(request.param("routing")); - existsRequest.minScore(request.paramAsFloat("min_score", DEFAULT_MIN_SCORE)); - existsRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); - existsRequest.preference(request.param("preference")); - - client.exists(existsRequest, new RestBuilderListener(channel) { - @Override - public RestResponse buildResponse(ExistsResponse response, XContentBuilder builder) throws Exception { - RestStatus status = response.exists() ? OK : NOT_FOUND; - builder.startObject(); - builder.field("exists", response.exists()); - builder.endObject(); - return new BytesRestResponse(status, builder); - } - }); - } -} diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 889a030999..6db9531af8 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -38,7 +38,6 @@ import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.exists.RestExistsAction; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestStatusToXContentListener; import org.elasticsearch.script.Template; @@ -80,14 +79,6 @@ public class RestSearchAction extends BaseRestHandler { controller.registerHandler(POST, "/{index}/_search/template", this); controller.registerHandler(GET, "/{index}/{type}/_search/template", this); controller.registerHandler(POST, "/{index}/{type}/_search/template", this); - - RestExistsAction restExistsAction = new RestExistsAction(settings, controller, client); - controller.registerHandler(GET, "/_search/exists", restExistsAction); - controller.registerHandler(POST, "/_search/exists", restExistsAction); - controller.registerHandler(GET, "/{index}/_search/exists", restExistsAction); - controller.registerHandler(POST, "/{index}/_search/exists", restExistsAction); - controller.registerHandler(GET, "/{index}/{type}/_search/exists", restExistsAction); - controller.registerHandler(POST, "/{index}/{type}/_search/exists", restExistsAction); } @Override -- cgit v1.2.3