How to set boost using constant score

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 :frowning: , I'd be very grateful.

Thanks a ton,
Crina

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

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

...

2 Likes

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 :slight_smile:
Thank uuu

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