2
votes

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.

1
I think you need to re-formulate the problem: what do you want to achieve given a certain mapping and some documents? You are mentioning boost (but boost exists in ES) and function_score, but are you sure this is the solution to the problem? What is the problem? Can you, please, reformulate the issue and say what you have, what you need to achieve and what have you tried so far and why you didn't like what you tried?Andrei Stefan
For example, you could use boosting fields with query dsl: elastic.co/guide/en/elasticsearch/reference/current/…Andrei Stefan

1 Answers

2
votes

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"]
        }
    }]
}