# Boosting results based on boolean field value

**URL:** <https://discuss.elastic.co/t/boosting-results-based-on-boolean-field-value/54979>\
**Category:** Elasticsearch\
**Created:** [July 7, 2016, 5:28pm UTC](https://discuss.elastic.co/t/boosting-results-based-on-boolean-field-value/54979 "2016-07-07T17:28:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bakhtiyor\_Homidov](https://avatars.discourse-cdn.com/v4/letter/b/51bf81/32.png) [@Bakhtiyor\_Homidov](https://discuss.elastic.co/u/Bakhtiyor_Homidov)\
**Post date:** [July 7, 2016, 5:28pm UTC](https://discuss.elastic.co/t/boosting-results-based-on-boolean-field-value/54979/1 "2016-07-07T17:28:44Z")

</div>

i found similar question [http://stackoverflow.com/questions/27569686/boosting-elasticsearch-based-on-boolean-field-value](http://stackoverflow.com/questions/27569686/boosting-elasticsearch-based-on-boolean-field-value), but the answer is incorrect, because it also returns all active articles which maybe to contain the word.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [July 7, 2016, 5:43pm UTC](https://discuss.elastic.co/t/boosting-results-based-on-boolean-field-value/54979/2 "2016-07-07T17:43:43Z")

</div>

Hi,

can you please restate the question and the problem you are trying to solve? Looking at the question/answert you linked to I can't clearly see the problem. It would be good to re-state the full problem you are facing here in the forum.

---

<div class="post-metadata">

**Author:** ![Bakhtiyor\_Homidov](https://avatars.discourse-cdn.com/v4/letter/b/51bf81/32.png) [@Bakhtiyor\_Homidov](https://discuss.elastic.co/u/Bakhtiyor_Homidov)\
**Post date:** [July 8, 2016, 12:01am UTC](https://discuss.elastic.co/t/boosting-results-based-on-boolean-field-value/54979/3 "2016-07-08T00:01:54Z")

</div>

hi,

e.g.  
I have a list of article, I want to get all the article where the word "louvre" is found inside the title.

And boost the active articles before the inactive ones. I still want to be able to see both active and inactive articles which the word "louvre" is found inside the titles. But on the top of the list fist the active ones, after that inactive

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [July 8, 2016, 9:05am UTC](https://discuss.elastic.co/t/boosting-results-based-on-boolean-field-value/54979/4 "2016-07-08T09:05:02Z")

</div>

So what is wrong with

```auto
{
  "query": {
    "bool": {
      "must": [
        {"match": {"title": "louvre"}}
      ],
      "should": [
        {"term": {"isActive": {"value": true}}}
      ]
    }
  }
}

```

I'd say this is doing what you want. If not, can you please state whats missing?

---

<div class="post-metadata">

**Author:** ![Bakhtiyor\_Homidov](https://avatars.discourse-cdn.com/v4/letter/b/51bf81/32.png) [@Bakhtiyor\_Homidov](https://discuss.elastic.co/u/Bakhtiyor_Homidov)\
**Post date:** [July 8, 2016, 4:29pm UTC](https://discuss.elastic.co/t/boosting-results-based-on-boolean-field-value/54979/5 "2016-07-08T16:29:55Z")

</div>

which i mentioned above, the query also returns any active articles and not looks to the title, the word contain in the title or not. it's just like `title.contains("louvre") OR isActive === true`

i want that it returns only articles which contain the word on the title, not just active articles.

---

<div class="post-metadata">

**Author:** ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)\
**Post date:** [July 8, 2016, 5:22pm UTC](https://discuss.elastic.co/t/boosting-results-based-on-boolean-field-value/54979/6 "2016-07-08T17:22:18Z")

</div>

This is a surprising result. Can you please provide a minimum reproduction including:

Create index with mapping

Index test documents with just title and value fields

Send search query

Show resulting document which doesn't have "louvre" in the title field.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 8, 2016, 5:31pm UTC](https://discuss.elastic.co/t/boosting-results-based-on-boolean-field-value/54979/7 "2016-07-08T17:31:26Z")

</div>

You can apply a custom scorer, with some caveats:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)

Since Lucene scores are only relevant inside each individual query and are  
only meant to order documents, there is no indication about what the  
eventual score will be. After profiling your existing queries, determine  
what you maximum score tends to be, and use this value as the floor for a  
boost. Inside a function score query, simply add this boost value to  
document that satisfy your requirements (active=true). In pseudo-code, it  
would be something like "script" : doc[active']==true ? \_score + 1000 :  
\_score"

Ivan

---

<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:36pm UTC](https://discuss.elastic.co/t/boosting-results-based-on-boolean-field-value/54979/8 "2017-07-05T22:36:58Z")

</div>


