# How to set boost using constant score

**URL:** <https://discuss.elastic.co/t/how-to-set-boost-using-constant-score/160258>\
**Category:** Elasticsearch\
**Created:** [December 10, 2018, 10:53pm UTC](https://discuss.elastic.co/t/how-to-set-boost-using-constant-score/160258 "2018-12-10T22:53:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CrinaGrigore](https://avatars.discourse-cdn.com/v4/letter/c/bbce88/32.png) [@CrinaGrigore](https://discuss.elastic.co/u/CrinaGrigore)\
**Post date:** [December 10, 2018, 10:53pm UTC](https://discuss.elastic.co/t/how-to-set-boost-using-constant-score/160258/1 "2018-12-10T22:53:47Z")

</div>

Hi,

I have the ES info structured as below:  
One example:  
"\_index": "content-media",  
"\_type": "default",  
"\_id": "335",  
"\_score": 1.0,  
"\_source": {  
"id": 335,  
"type": "ALBUM",  
"title": "Brighter Wounds",  
"description": "Album",  
"category": [{"name": "Alternative"}],  
"artist": "Son Lux",  
"cast": ,  
"tag": [{"id": 5}],  
"status": "PUBLISHED",  
"discoverable": true

And I'm just trying to **prioritise** the **title field** using the boost : `fields: ['title^2', 'description', 'cast.name', 'artist']` while using a multi\_match query as below:

```
body: {
  query:
  {
    constant_score: {
      filter: {
        bool: {
          must: {
            multi_match: {
                query: 'test',
                type: 'phrase_prefix',
                 slop: 5,
                 fields: ['title^2', 'description', 'cast.name', 'artist'],
                 operator: 'AND'
            }
          },
          should: [{
            bool: {
              must: [
                { match: { 'type': ‘ALBUM’ } },
                { match: { 'discoverable': true } },
                { match: { 'status': 'PUBLISHED' } },
                { match: { 'tag.id': 5 } }
              ]
            }
          }
          ]
        }
      }
    }
  },
  aggs: {
    'by_top_first': {
      terms: {
        field: 'title.keyword'
      },
      aggs: {
        'by_top_hit': { top_hits: { size: 1 } },
        'max_score': { max: { script: '_score' } }
      }
    },
    'by_type': {
      terms: {
        field: 'type.keyword',
         size: 4
      },
      aggs: {
        'by_top_hit': { top_hits: { size: 6 } },
        'max_score': { max: { script: '_score' } }
      }
    },
  }
}

```

Boost is not working as expected. I really need some help here ☹ , I'd be very grateful.

Thanks a ton,  
Crina

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [December 11, 2018, 12:14am UTC](https://discuss.elastic.co/t/how-to-set-boost-using-constant-score/160258/2 "2018-12-11T00:14:49Z")

</div>

I would recommend getting familiar with looking at your query explain. A tool like [splainer.io](http://splainer.io) might be able to help /  
[https://github.com/o19s/splainer](https://github.com/o19s/splainer)

[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-explain.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-explain.html)

Here the answer is probably that constant score query nullifies any boosting, just giving every doc the same score.

Doug

...

---

<div class="post-metadata">

**Author:** ![CrinaGrigore](https://avatars.discourse-cdn.com/v4/letter/c/bbce88/32.png) [@CrinaGrigore](https://discuss.elastic.co/u/CrinaGrigore)\
**Post date:** [December 11, 2018, 7:54am UTC](https://discuss.elastic.co/t/how-to-set-boost-using-constant-score/160258/3 "2018-12-11T07:54:45Z")

</div>

Hey Doug, Indeed - constant score is nullifying the boost, really thanks for that. I fixed it removing  
`constant_score: { filter: {` . I was totally convinced that I cannot filter without them 🙂  
Thank uuu

---

<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:** [January 8, 2019, 7:54am UTC](https://discuss.elastic.co/t/how-to-set-boost-using-constant-score/160258/4 "2019-01-08T07:54:45Z")

</div>

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