diff --git a/src/main/java/org/elasticsearch/percolator/PercolatorService.java b/src/main/java/org/elasticsearch/percolator/PercolatorService.java index d832379b05c..5758dbb8a3b 100644 --- a/src/main/java/org/elasticsearch/percolator/PercolatorService.java +++ b/src/main/java/org/elasticsearch/percolator/PercolatorService.java @@ -47,6 +47,7 @@ import org.elasticsearch.common.lucene.HashedBytesRef; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.XCollector; import org.elasticsearch.common.lucene.search.XConstantScoreQuery; +import org.elasticsearch.common.lucene.search.XFilteredQuery; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.text.BytesText; import org.elasticsearch.common.text.StringText; @@ -781,7 +782,7 @@ public class PercolatorService extends AbstractComponent { private void queryBasedPercolating(Engine.Searcher percolatorSearcher, PercolateContext context, QueryCollector percolateCollector) throws IOException { Filter percolatorTypeFilter = context.indexService().mapperService().documentMapper(TYPE_NAME).typeFilter(); percolatorTypeFilter = context.indexService().cache().filter().cache(percolatorTypeFilter); - FilteredQuery query = new FilteredQuery(context.percolateQuery(), percolatorTypeFilter); + XFilteredQuery query = new XFilteredQuery(context.percolateQuery(), percolatorTypeFilter); percolatorSearcher.searcher().search(query, percolateCollector); for (Collector queryCollector : percolateCollector.facetAndAggregatorCollector) { diff --git a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java index 4e2f66aff8f..38ea797f218 100644 --- a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java +++ b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java @@ -1774,6 +1774,29 @@ public class PercolatorTests extends ElasticsearchIntegrationTest { assertThat(((Map) properties.get("field2")).get("type"), equalTo("string")); } + @Test + public void testDontReportDeletedPercolatorDocs() throws Exception { + client().admin().indices().prepareCreate("test").execute().actionGet(); + ensureGreen(); + + client().prepareIndex("test", PercolatorService.TYPE_NAME, "1") + .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()) + .get(); + client().prepareIndex("test", PercolatorService.TYPE_NAME, "1") + .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()) + .get(); + refresh(); + + PercolateResponse response = client().preparePercolate() + .setIndices("test").setDocumentType("type") + .setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field", "value").endObject())) + .setPercolateFilter(FilterBuilders.matchAllFilter()) + .get(); + assertMatchCount(response, 1l); + assertThat(response.getMatches(), arrayWithSize(1)); + assertThat(convertFromTextArray(response.getMatches(), "test"), arrayContainingInAnyOrder("1")); + } + void initNestedIndexAndPercolation() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder(); mapping.startObject().startObject("properties").startObject("companyname").field("type", "string").endObject()