# Filter only returns less results results than same filter combined with a must match query

**URL:** <https://discuss.elastic.co/t/filter-only-returns-less-results-results-than-same-filter-combined-with-a-must-match-query/23154>\
**Category:** Elasticsearch\
**Created:** [April 8, 2015, 4:37pm UTC](https://discuss.elastic.co/t/filter-only-returns-less-results-results-than-same-filter-combined-with-a-must-match-query/23154 "2015-04-08T16:37:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_R](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Chris\_R](https://discuss.elastic.co/u/Chris_R)\
**Post date:** [April 8, 2015, 4:37pm UTC](https://discuss.elastic.co/t/filter-only-returns-less-results-results-than-same-filter-combined-with-a-must-match-query/23154/1 "2015-04-08T16:37:33Z")

</div>

I am struggling to understand why a filter only returns older results than  
that same filter combined with a must match query.

More specifically, a prefix filter on a field which contains a link will  
return items which are two days old. However, that same filter added with a  
must match query will return more recent recent results, and whose link  
should fit in the prefix filter. In terms of recency, I am doing a Gaussian  
filter on the date for both ES requests. Both requests and their diff are  
below.

I am very confused so any hint will help, thanks.

Chris.

P.S.: Both queries are generated using elasticsearch\_dsl-py and  
bungiesearch (a Django helper for ES\_dsl-py of which I am the maintainer).

Here is the query which returns more recent results:  
{  
"query" : {  
"filtered" : {  
"filter" : {  
"bool" : {  
"must" : [  
{  
"or" : {  
"filters" : [ {  
"term" : {  
"blacklisted" : False  
}  
}, {  
"missing" : {  
"field" : "blacklisted"  
}  
} ]  
}  
},  
{  
"or" : {  
"filters" : [ {  
"term" : {  
"is\_duplicate" : False  
}  
}, {  
"missing" : {  
"field" : "is\_duplicate"  
}  
} ]  
}  
},  
{  
"or" : {  
"filters" : [  
{  
"terms" : {  
"publication\_name" :   
}  
},  
{  
"prefix" : {  
"link" :  
"[http://www.ncbi.nlm.nih.gov/pubmed/](http://www.ncbi.nlm.nih.gov/pubmed/)"  
}  
} ]  
}  
} ]  
}  
},  
"query" : {  
"bool" : {  
"must" : [ {  
"match" : {  
"\_all" : {  
"operator" : "and",  
"query" : "cancer"  
}  
}  
}, {  
"function\_score" : {  
"score\_mode" : "sum",  
"boost" : 20,  
"functions" : [ {  
"gauss" : {  
"published" : {  
"origin" : "2015-04-08",  
"decay" : 0.95,  
"scale" : "15d",  
"offset" : "4d"  
}  
}  
} ],  
"boost\_mode" : "multiply"  
}  
} ]  
}  
}  
}  
},  
"fields" : "\_source"  
}

Here is the query which returns the older results:  
{  
"query" : {  
"filtered" : {  
"filter" : {  
"bool" : {  
"must" : [  
{  
"or" : {  
"filters" : [ {  
"term" : {  
"blacklisted" : False  
}  
}, {  
"missing" : {  
"field" : "blacklisted"  
}  
} ]  
}  
},  
{  
"or" : {  
"filters" : [ {  
"term" : {  
"is\_duplicate" : False  
}  
}, {  
"missing" : {  
"field" : "is\_duplicate"  
}  
} ]  
}  
},  
{  
"or" : {  
"filters" : [  
{  
"terms" : {  
"publication\_name" :   
}  
},  
{  
"prefix" : {  
"link" :  
"[http://www.ncbi.nlm.nih.gov/pubmed/](http://www.ncbi.nlm.nih.gov/pubmed/)"  
}  
} ]  
}  
} ]  
}  
},  
"query" : {  
"function\_score" : {  
"score\_mode" : "sum",  
"boost" : 20,  
"functions" : [ {  
"gauss" : {  
"published" : {  
"origin" : "2015-04-08",  
"decay" : 0.95,  
"scale" : "15d",  
"offset" : "4d"  
}  
}  
} ],  
"boost\_mode" : "multiply"  
}  
}  
}  
},  
"fields" : "\_source"  
}

## Here is the diff between both JSON: 51,56c51,60 \< "bool" : { \< "must" : [ { \< "match" : { \< "\_all" : { \< "operator" : "and", \< "query" : "cancer"

> ```
> "function_score" : {
> "score_mode" : "sum",
> "boost" : 20,
> "functions" : [ {
> "gauss" : {
> "published" : {
> "origin" : 
> 
> ```

"2015-04-08",

> ```
> "decay" : 
> 
> ```

0.95,

> ```
> "scale" : 
> 
> ```

"15d",

> ```
> "offset" : 
> 
> ```

## "4d" 59,75c63,64 \< }, { \< "function\_score" : { \< "score\_mode" : "sum", \< "boost" : 20, \< "functions" : [{ \< "gauss" : { \< "published" : { \< "origin" : "2015-04-08", \< "decay" : 0.95, \< "scale" : "15d", \< "offset" : "4d" \< } \< } \< }], \< "boost\_mode" : "multiply" \< } \< } ]

> ```
> } ],
> "boost_mode" : "multiply"
> 
> ```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b3d6488d-9c13-48ba-ab0a-02df76d8e2f0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b3d6488d-9c13-48ba-ab0a-02df76d8e2f0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:20am UTC](https://discuss.elastic.co/t/filter-only-returns-less-results-results-than-same-filter-combined-with-a-must-match-query/23154/2 "2017-07-06T00:20:50Z")

</div>

Closed on July 6, 2017, 12:20am UTC


