|
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.index.IndexRequestBuilder;
|
25 | 28 | import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
|
28 | 31 | import org.elasticsearch.bootstrap.JavaVersion;
|
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.time.DateFormatter;
|
33 | 37 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
@@ -1892,4 +1896,20 @@ public void testFieldAliasesForMetaFields() throws Exception {
|
1892 | 1896 | }
|
1893 | 1897 |
|
1894 | 1898 | }
|
| 1899 | + |
| 1900 | + /** |
| 1901 | + * Test correct handling {@link SpanBooleanQueryRewriteWithMaxClause#rewrite(IndexReader, MultiTermQuery)}. That rewrite method is e.g. |
| 1902 | + * set for fuzzy queries with "constant_score" rewrite nested inside a `span_multi` query and would cause NPEs due to an unset |
| 1903 | + * {@link AttributeSource}. |
| 1904 | + */ |
| 1905 | + public void testIssueFuzzyInsideSpanMulti() { |
| 1906 | + createIndex("test"); |
| 1907 | + client().prepareIndex("test", "_doc", "1").setSource("field", "foobarbaz").get(); |
| 1908 | + ensureGreen(); |
| 1909 | + refresh(); |
| 1910 | + |
| 1911 | + BoolQueryBuilder query = boolQuery().filter(spanMultiTermQueryBuilder(fuzzyQuery("field", "foobarbiz").rewrite("constant_score"))); |
| 1912 | + SearchResponse response = client().prepareSearch("test").setQuery(query).get(); |
| 1913 | + assertHitCount(response, 1); |
| 1914 | + } |
1895 | 1915 | }
|
0 commit comments