Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.lucene.search.spans.SpanOrQuery;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.BytesRef;

import java.io.IOException;
Expand Down Expand Up @@ -92,11 +93,12 @@ private Collection<SpanQuery> collectTerms(IndexReader reader, MultiTermQuery qu
continue;
}

final TermsEnum termsEnum = getTermsEnum(query, terms, null);
final TermsEnum termsEnum = getTermsEnum(query, terms, new AttributeSource());
assert termsEnum != null;

if (termsEnum == TermsEnum.EMPTY)
if (termsEnum == TermsEnum.EMPTY) {
continue;
}

BytesRef bytes;
while ((bytes = termsEnum.next()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.elasticsearch.search.query;

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.join.ScoreMode;
import org.apache.lucene.util.English;
import org.elasticsearch.action.index.IndexRequestBuilder;
Expand All @@ -28,6 +30,7 @@
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.bootstrap.JavaVersion;
import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.lucene.search.SpanBooleanQueryRewriteWithMaxClause;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.unit.Fuzziness;
Expand Down Expand Up @@ -1758,4 +1761,19 @@ public void testFieldAliasesForMetaFields() throws Exception {
}

}

/**
* Test fix for NPE from {@link SpanBooleanQueryRewriteWithMaxClause#rewrite(IndexReader, MultiTermQuery)}.
* See https://github.com/elastic/elasticsearch/issues/52894 for details
*/
public void testIssue52894() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change to a more descriptive name ? I don't think we should add a link to an issue in the comment either. This test checks that span_fuzzy query are correctly handled and #52894 revealed that it was missing.

createIndex("test");
client().prepareIndex("test").setId("1").setSource("field", "foobarbaz").get();
ensureGreen();
refresh();

BoolQueryBuilder query = boolQuery().filter(spanMultiTermQueryBuilder(fuzzyQuery("field", "foobarbiz").rewrite("constant_score")));
SearchResponse response = client().prepareSearch("test").setQuery(query).get();
assertHitCount(response, 1);
}
}