|
19 | 19 |
|
20 | 20 | package org.elasticsearch.search.query;
|
21 | 21 |
|
| 22 | +import org.apache.lucene.index.IndexReader; |
| 23 | +import org.apache.lucene.search.MultiTermQuery; |
22 | 24 | import org.apache.lucene.search.join.ScoreMode;
|
| 25 | +import org.apache.lucene.util.AttributeSource; |
23 | 26 | import org.apache.lucene.util.English;
|
24 | 27 | import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
25 | 28 | import org.elasticsearch.action.index.IndexRequestBuilder;
|
|
28 | 31 | import org.elasticsearch.action.search.SearchType;
|
29 | 32 | import org.elasticsearch.common.Strings;
|
30 | 33 | import org.elasticsearch.common.document.DocumentField;
|
| 34 | +import org.elasticsearch.common.lucene.search.SpanBooleanQueryRewriteWithMaxClause; |
31 | 35 | import org.elasticsearch.common.settings.Settings;
|
32 | 36 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
33 | 37 | import org.elasticsearch.common.xcontent.XContentFactory;
|
@@ -1946,4 +1950,20 @@ public void testFieldAliasesForMetaFields() throws Exception {
|
1946 | 1950 | DocumentField field = hit.getFields().get("id-alias");
|
1947 | 1951 | assertThat(field.getValue().toString(), equalTo("1"));
|
1948 | 1952 | }
|
| 1953 | + |
| 1954 | + /** |
| 1955 | + * Test correct handling {@link SpanBooleanQueryRewriteWithMaxClause#rewrite(IndexReader, MultiTermQuery)}. That rewrite method is e.g. |
| 1956 | + * set for fuzzy queries with "constant_score" rewrite nested inside a `span_multi` query and would cause NPEs due to an unset |
| 1957 | + * {@link AttributeSource}. |
| 1958 | + */ |
| 1959 | + public void testIssueFuzzyInsideSpanMulti() { |
| 1960 | + createIndex("test"); |
| 1961 | + client().prepareIndex("test", "_doc", "1").setSource("field", "foobarbaz").get(); |
| 1962 | + ensureGreen(); |
| 1963 | + refresh(); |
| 1964 | + |
| 1965 | + BoolQueryBuilder query = boolQuery().filter(spanMultiTermQueryBuilder(fuzzyQuery("field", "foobarbiz").rewrite("constant_score"))); |
| 1966 | + SearchResponse response = client().prepareSearch("test").setQuery(query).get(); |
| 1967 | + assertHitCount(response, 1); |
| 1968 | + } |
1949 | 1969 | }
|
0 commit comments