NPE for POST mode facets if facet_filter gives no document.
Closes #3479.
This commit is contained in:
parent
5c7d7fb399
commit
83c26eb74a
|
@ -66,12 +66,14 @@ public abstract class FacetExecutor {
|
|||
for (int i = 0; i < docSets.size(); i++) {
|
||||
ContextDocIdSet entry = docSets.get(i);
|
||||
DocIdSet filteredSet = filter.getDocIdSet(entry.context, null);
|
||||
if (filteredSet != null) {
|
||||
filteredEntries.add(new ContextDocIdSet(
|
||||
entry.context,
|
||||
// TODO: can we be smart here, maybe AndDocIdSet is not always fastest?
|
||||
new AndDocIdSet(new DocIdSet[]{entry.docSet, filteredSet})
|
||||
));
|
||||
}
|
||||
}
|
||||
post.executePost(filteredEntries);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|||
import static org.elasticsearch.index.query.FilterBuilders.termFilter;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.elasticsearch.search.facet.FacetBuilders.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
|
@ -2282,6 +2281,29 @@ public class SimpleFacetsTests extends AbstractSharedClusterTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test // #3479: Null pointer exception for POST mode facets if facet_filter accepts no documents
|
||||
public void testFilterFacetWithFacetFilterPostMode() throws IOException {
|
||||
client().prepareIndex("test", "type1").setSource(jsonBuilder().startObject()
|
||||
.field("field", "xxx")
|
||||
.endObject()).execute().actionGet();
|
||||
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
|
||||
for (int i = 0; i < numberOfRuns(); i++) {
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.addFacet(
|
||||
termsFacet("facet1").field("field").mode(FacetBuilder.Mode.POST).facetFilter(termFilter("tag", "doesnotexist"))
|
||||
)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.getFailedShards(), equalTo(0));
|
||||
TermsFacet facet = searchResponse.getFacets().facet("facet1");
|
||||
assertThat(facet.getName(), equalTo("facet1"));
|
||||
assertThat(facet.getEntries().size(), equalTo(0));
|
||||
}
|
||||
}
|
||||
|
||||
private long utcTimeInMillis(String time) {
|
||||
return timeInMillis(time, DateTimeZone.UTC);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue