What is the boost factor of a should in a bool_query?

Hi,

I'm a newbie to elasticsearch and couldn't find the answer to this in the online docs.

I have a bool_query with a must and a should. As I wanted the should part causes those results to be boosted.

However, what I can't find is what the default boost factor is when a should is matched? Is it possible to tweak this default boost factor?

Thank you

Welcome!

There's no "boost" factor as per say for should condition. It "just" adds the score of the should clauses to the score of the must clauses. Which effectively makes documents scoring higher.

thanks dadoonet.

So different types of shoulds would have different scores?

In my current tests it seems to add 1 to the score when it matches the should.

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Sure dadoonet:

Index:

{
    "settings": {
        "analysis": {
            "analyzer": {
                "auto_complete_a": {
                    "tokenizer": "whitespace",
                    "filter": [
                        "lowercase",
                        "filter_a"
                    ]
                }
            },
            "filter": {
                "filter_a": {
                    "type": "edge_ngram",
                    "min_gram": 3,
                    "max_gram": 7
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "name": {
                "type": "text",
                "analyzer": "auto_complete_a"
            },
            "sku": {
                "type": "text"
            }
        }
    }
}

Using this query the matching record for 111111 is scored 16.67

{
    "query": {
        "bool": {
            "must": {
                "multi_match": {
                    "query": "sony"
                }
            },
            "should": {
                "terms": {
                    "sku": ["111111", "222222"]
                }
            }
        }
    }
}

However changing the should to a filter scores it as 15.67

{
    "query": {
        "bool": {
            "must": {
                "multi_match": {
                    "query": "sony"
                }
            },
            "filter": {
                "terms": {
                    "sku": ["111111", "222222"]
                }
            }
        }
    }
}

That's why I assumed that the should would add a score of 1

I can't reproduce without data. Could you share a full script please?

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