0
votes

I have a query with a bunch of "filter": [] Then a bunch of scoring functions:

"must": [ { "function_score": { "functions": [ ... ] } } ]

I am trying to have documents with a specific keyword to rank higher than if they dont have it.

I tried to add this into my functions array:

{
    "filter": {
        "match": {
            "[MY FIELD]": "[MY KEYWORD]"
        }
    },
    "weight": 1
}

But I think it is doing the opposite, it is adding a coefficient below 1 to the one which match and therefor making the document with MY KEYWORD to rank lower.

I tried to search for a not method to match for all the one without MY KEYWORD but I cannot find anything in the context of functions. I found match_not but it doesnt work there.

My goal is if you have 2 exact same documents, one with MY KEYWORD and one without, I want to one with to have a higher score.

Thank you.

1

1 Answers

0
votes

The one solution I found is:

{
    "script_score" : {
        "script" : {
          "inline": "String tmp = null; for (a in doc['MY_FIELD']) {tmp = a;} return tmp == 'MY_KEYWORD' ? 1.0 : DECAY_VALUE",
          "lang": "painless"
        }
    },
    "weight": MY_WEIGHT
}

I used a decay_value of 0.7

and a weight of 0.7 too.

And MY_FIELD needs to be a type:keyword