Skip to content

Commit edb23bd

Browse files
committed
Skip old queries on search shards
Changes the `search_shards` api to skip sending unsupported queries, instead sending `match_all` which should make it "fail open", returning "this shard can match this query" for all unsupported queries. This is *weird*, but it's useful for systems that build the query internally inside of elasticsearch and can fall back to filtering outside of lucene. Which is *exactly* what ESQL does.
1 parent f2cf76f commit edb23bd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

server/src/main/java/org/elasticsearch/action/search/SearchShardsRequest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.common.io.stream.StreamInput;
1717
import org.elasticsearch.common.io.stream.StreamOutput;
1818
import org.elasticsearch.core.Nullable;
19+
import org.elasticsearch.index.query.MatchAllQueryBuilder;
1920
import org.elasticsearch.index.query.QueryBuilder;
2021
import org.elasticsearch.tasks.Task;
2122
import org.elasticsearch.tasks.TaskId;
@@ -77,7 +78,16 @@ public void writeTo(StreamOutput out) throws IOException {
7778
super.writeTo(out);
7879
out.writeStringArray(indices);
7980
indicesOptions.writeIndicesOptions(out);
80-
out.writeOptionalNamedWriteable(query);
81+
out.writeOptionalNamedWriteable(
82+
query == null || query.supportsVersion(out.getTransportVersion()) ? query :
83+
/*
84+
* The remote node doesn't support the query we're sending. If this were only
85+
* used for _search this could just fail, but for ESQL it's much more convenient
86+
* if it pretends that the query is MatchAll. ESQL will frequently be able to
87+
* perform the document filtering on the data node in its engine. Slowly.
88+
* But correctly.
89+
*/
90+
new MatchAllQueryBuilder());
8191
out.writeOptionalString(routing);
8292
out.writeOptionalString(preference);
8393
out.writeBoolean(allowPartialSearchResults);

0 commit comments

Comments
 (0)