Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Added query/filter wrapper that builds the actual query to be e…
…xecuted on the last possible moment to aid with index aliases and percolator queries using `now` date expression. Percolator queries and index alias filters are parsed once and reused as long as they exist on a node. If they contain time based range filters with a `now` expression then the alias filters and percolator queries are going to be incorrect from the moment these are constructed (depending on the date rounding). If a range filter or range query is constructed as part of adding a percolator query or a index alias filter then these get wrapped in special query or filter wrappers that defer the resolution of now at last possible moment as apposed during parse time. In the case of the range filter a special Resolvable Filter makes sure that `now` is resolved when the DocIdSet is pulled and in the case of the range query `now` is resolved at query rewrite time. Both occur at the time the range filter or query is used as apposed when the query or filter is constructed during parse time. Closes #8474 Closes #8534
- Loading branch information
Showing
11 changed files
with
337 additions
and
42 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/org/elasticsearch/common/lucene/search/NoCacheQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.common.lucene.search; | ||
|
||
import org.apache.lucene.search.Query; | ||
|
||
/** | ||
* Queries are never cached directly, but a query can be wrapped in a filter that may end being cached. | ||
* Filters that wrap this query either directly or indirectly will never be cached. | ||
*/ | ||
public abstract class NoCacheQuery extends Query { | ||
|
||
@Override | ||
public final String toString(String s) { | ||
return "no_cache(" + innerToString(s) + ")"; | ||
} | ||
|
||
public abstract String innerToString(String s); | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/elasticsearch/common/lucene/search/ResolvableFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.common.lucene.search; | ||
|
||
import org.apache.lucene.index.LeafReaderContext; | ||
import org.apache.lucene.search.DocIdSet; | ||
import org.apache.lucene.search.Filter; | ||
import org.apache.lucene.util.Bits; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* A filter implementation that resolves details at the last possible moment between filter parsing and execution. | ||
* For example a date filter based on 'now'. | ||
*/ | ||
public abstract class ResolvableFilter extends Filter { | ||
|
||
/** | ||
* @return The actual filter instance to be executed containing the latest details. | ||
*/ | ||
public abstract Filter resolve(); | ||
|
||
|
||
|
||
@Override | ||
public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) throws IOException { | ||
Filter resolvedFilter = resolve(); | ||
if (resolvedFilter != null) { | ||
return resolvedFilter.getDocIdSet(context, acceptDocs); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.