# Elastic Search: How to set constant score for only one of the queries

**URL:** <https://discuss.elastic.co/t/elastic-search-how-to-set-constant-score-for-only-one-of-the-queries/105310>\
**Category:** Elasticsearch\
**Created:** [October 25, 2017, 11:04pm UTC](https://discuss.elastic.co/t/elastic-search-how-to-set-constant-score-for-only-one-of-the-queries/105310 "2017-10-25T23:04:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Renz\_Rollon](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Renz\_Rollon](https://discuss.elastic.co/u/Renz_Rollon)\
**Post date:** [October 25, 2017, 11:04pm UTC](https://discuss.elastic.co/t/elastic-search-how-to-set-constant-score-for-only-one-of-the-queries/105310/1 "2017-10-25T23:04:38Z")

</div>

Using ElasticSearch 2.3,

I have a query like:  
{  
"query" : {  
"bool" : {  
"should" : [{  
"query\_string" : {  
"query" : "fullName:("guy")"  
}  
}, {  
"query\_string" : {  
"query" : "nickName:("guy")"  
}  
}, {  
"term" : {  
"fullExactName" : "guy"  
}  
}  
]  
}  
},  
"sort" : [{  
"\_score" : {  
"order" : "desc"  
}  
}, {  
"fullExactName" : {  
"order" : "asc"  
}  
}  
]  
}

How can I assign constant scores to records that match each of the query?

- Assign all records matching **nickName** query a constant \_score of **1**
- Assign all records matching **fullName** query a constant \_score of **2**
- Assign all records matching **fullExactName** query a constant \_score of **3**

I need the scores to be equal so I can still sort them alphabetically.

Thanks!

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [October 27, 2017, 4:45pm UTC](https://discuss.elastic.co/t/elastic-search-how-to-set-constant-score-for-only-one-of-the-queries/105310/2 "2017-10-27T16:45:24Z")

</div>

You can wrap the queries with a `constant_score` query, which assigns a score based on the boost: [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html)

Note: scores will be combined if the document matches multiple parts of the query. If you want _only_ one score to be added, you'll need to setup the various logical combinations.

E.g. `+nickName NOT (fullName OR fullExactName)`, `+fullName NOT (nickName OR fullExactName)`, etc. That way only one score is applied.

---

<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:** [November 24, 2017, 4:45pm UTC](https://discuss.elastic.co/t/elastic-search-how-to-set-constant-score-for-only-one-of-the-queries/105310/3 "2017-11-24T16:45:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
