From aa6cd93e0f860faf869e46386beea3836f635816 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 2 Nov 2016 09:48:49 +0100 Subject: Require arguments for QueryShardContext creation. (#21196) The `IndexService#newQueryShardContext()` method creates a QueryShardContext on shard `0`, with a `null` reader and that uses `System.currentTimeMillis()` to resolve `now`. This may hide bugs, since the shard id is sometimes used for query parsing (it is used to salt random score generation in `function_score`), passing a `null` reader disables query rewriting and for some use-cases, it is simply not ok to rely on the current timestamp (eg. percolation). So this pull request removes this method and instead requires that all call sites provide these parameters explicitly. --- .../main/java/org/elasticsearch/index/query/QueryRewriteContext.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java') diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java index ccca0af652..c8b5cf174f 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java @@ -86,7 +86,9 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier { return mapperService; } - /** Return the current {@link IndexReader}, or {@code null} if we are on the coordinating node. */ + /** Return the current {@link IndexReader}, or {@code null} if no index reader is available, for + * instance if we are on the coordinating node or if this rewrite context is used to index + * queries (percolation). */ public IndexReader getIndexReader() { return reader; } -- cgit v1.2.3