Add support for IndexOrDocValuesQuery in FieldExtractor (elastic/x-pack-elasticsearch#976)

This commit adds support for extracting the fields from a IndexOrDocValuesQuery so that we can
still take advantage of the cache when this query is used.

relates elastic/x-pack-elasticsearch#973

Original commit: elastic/x-pack-elasticsearch@0b97202a41
This commit is contained in:
Jay Modi 2017-04-06 12:44:25 +01:00 committed by GitHub
parent 573b421446
commit 92942c9327
2 changed files with 20 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.DocValuesNumbersQuery;
import org.apache.lucene.search.DocValuesRangeQuery;
import org.apache.lucene.search.FieldValueQuery;
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.MultiPhraseQuery;
@ -78,6 +79,9 @@ class FieldExtractor {
fields.add(((FieldValueQuery)query).getField());
} else if (query instanceof DocValuesNumbersQuery) {
fields.add(((DocValuesNumbersQuery)query).getField());
} else if (query instanceof IndexOrDocValuesQuery) {
extractFields(((IndexOrDocValuesQuery) query).getIndexQuery(), fields);
extractFields(((IndexOrDocValuesQuery) query).getRandomAccessQuery(), fields);
} else if (query instanceof DocValuesRangeQuery) {
fields.add(((DocValuesRangeQuery)query).getField());
} else if (query instanceof MatchAllDocsQuery) {

View File

@ -14,6 +14,7 @@ import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.DocValuesNumbersQuery;
import org.apache.lucene.search.DocValuesRangeQuery;
import org.apache.lucene.search.FieldValueQuery;
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.MultiPhraseQuery;
@ -135,4 +136,19 @@ public class FieldExtractorTests extends ESTestCase {
FieldExtractor.extractFields(new AssertingQuery(random(), new MatchAllDocsQuery()), fields);
});
}
public void testIndexOrDocValuesQuery() {
Set<String> fields = new HashSet<>();
IndexOrDocValuesQuery query = new IndexOrDocValuesQuery(new FieldValueQuery("foo"),
new DocValuesNumbersQuery("foo", 5L));
FieldExtractor.extractFields(query, fields);
assertEquals(asSet("foo"), fields);
// what if they have different fields - some programming error
fields.clear();
query = new IndexOrDocValuesQuery(new FieldValueQuery("foo1"),
new DocValuesNumbersQuery("bar", 5L));
FieldExtractor.extractFields(query, fields);
assertEquals(asSet("foo1", "bar"), fields);
}
}