# "Non scoring" queries

**URL:** https://discuss.elastic.co/t/non-scoring-queries/53880
**Category:** Elasticsearch
**Created:** [June 24, 2016, 10:26am UTC](https://discuss.elastic.co/t/non-scoring-queries/53880 "2016-06-24T10:26:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![andrea\_patricelli](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@andrea\_patricelli](https://discuss.elastic.co/u/andrea_patricelli)
#### Post date: [June 24, 2016, 10:26am UTC](https://discuss.elastic.co/t/non-scoring-queries/53880/1 "2016-06-24T10:26:51Z")

</div>

Hi,

I'm coming with 1.X experience and I'm facing with some 2.X new features and radical changes. I'm a bit confused.  
in this part of the documentation you talk about filters and queries: [https://www.elastic.co/guide/en/elasticsearch/guide/current/\_queries\_and\_filters.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/_queries_and_filters.html)

From my understanding ES 2.X do not have separation between queries and filters anymore.  
So what kind of construct do I have to use if I want do migrate a filter from 1.X to a query in 2.X?  
If I want only the result (a direct answer) regardless of the score what kind of constructs do I have to use (possibly in Java API)?

Example:

How can I implement a **non scoring** query?

this way?

`QueryBuilders.boolQuery().must( QueryBuilders.matchAllQuery() ).filter( QueryBuilders.termsQuery( "id", references ) );`

Is this a non scoring query?  
If I want more performant cosntructs can I bypass filters and use queries in another way?

Thanks for any help and regards,  
Andrea

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [June 24, 2016, 12:30pm UTC](https://discuss.elastic.co/t/non-scoring-queries/53880/2 "2016-06-24T12:30:04Z")

</div>

> [@andrea\_patricelli](#):
>
> So what kind of construct do I have to use if I want do migrate a filter from 1.X to a query in 2.X?

Lookup the query alternative for your filter (most filters have the same settings and name as their query alternative. For example range filter -\> range query ) and wrap it in a `bool` query's `filter` clause.

> [@andrea\_patricelli](#):
>
> QueryBuilders.boolQuery().must( QueryBuilders.matchAllQuery() ).filter( QueryBuilders.termsQuery( "id", references ) );
> 
> Is this a non scoring query?

Yes, the `filter` method makes queries non scoring. In your example the must clause with the match all query is not needed. Your query will be more performant if you remove this must clause.

---

<div class="post-metadata">

### Author: ![andrea\_patricelli](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@andrea\_patricelli](https://discuss.elastic.co/u/andrea_patricelli)
#### Post date: [June 28, 2016, 9:26am UTC](https://discuss.elastic.co/t/non-scoring-queries/53880/3 "2016-06-28T09:26:33Z")

</div>

Hi Martin,

Thank you very much for the answer.  
I've another little doubt.  
If do I have to perform a "not" query?  
I saw from [1] that not filter and not query have been replaced by boolean `must_not`. But isn't must\_not bool query scoring? If I want a "non-scoring" bool `must_not`?

for example:  
`QueryBuilders.boolQuery().filter( query ).mustNot( QueryBuilders.existsQuery( "alias" ) );`

Does `mustNot` contribute to scoring? I guess no, but want only to be sure.

[1] [https://www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-not-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-not-query.html)

Best regards,  
Andrea

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [June 28, 2016, 9:40am UTC](https://discuss.elastic.co/t/non-scoring-queries/53880/4 "2016-06-28T09:40:23Z")

</div>

No, `must_not` clauses never contribute to scoring. Only a `bool` query's `must` and `should` clauses contribute to scoring.

---

<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 5, 2017, 10:39pm UTC](https://discuss.elastic.co/t/non-scoring-queries/53880/5 "2017-07-05T22:39:59Z")

</div>


