elasticsearchlucenesolr-boost

Elasticsearch boost per field with function score


I have a query with different query data for different fields and ORed results. I also want to favor hits with certain fields. Ideally this would only increase ranking but would not cause results that did not contain some of the terms in the other fields. This would skew results towards those that have certain fields.

I think this used to be called a boost but since boost has been removed from Lucene Elasticsearch has replaced them with function scores and I don't understand how to add them to my query.

The query looks like this:

POST /index/type/_search
{
    "query": {
        "bool": {
            "should": [{
                "terms": {
                    "field1": ["67", "93", "73", "78", "88", "77"]
                }
            }, {
                "terms": {
                    "field2": ["68", "94", "72", "76", "82", "96", "70", "86", "81", "92", "97", "74", "91", "85"]
                }
            }, {
                "terms": {
                    "category": ["cat2"]
                }
            }]
        }
    }
}

Of all possible hits, I'd like to skew ranking towards those with terms from the catagory field.


Solution

  • The _boost field (document-level boost) was removed, but field-level boosts, and query boosts still work just fine. It looks like you are looking for query boosts.

    So, if you wanted to boost matches on field1:

    "bool": {
        "should": [{
            "terms": {
                "field1": ["67", "93", "73", "78", "88", "77"],
                "boost": 2.0
            }
        }, {
            "terms": {
                "field2": ["68", "94", "72", "76", "82", "96", "70", "86", "81", "92", "97", "74", "91", "85"]
            }
        }, {
            "terms": {
                "category": ["cat2"]
            }
        }]
    }