简体   繁体   中英

adding boost by field to a prefix and match_phrase_prefix queries

I am trying to add score boost to different fields in my es query so that a certain field will have precedence over another.

My query looks like this:

"query": {
    "bool": {
        "should": [{
            "prefix": {
               "title": "נפצ"
            }},{
            "match_phrase_prefix": {
               "sub_title": "נפצע קש"
            }
        }]
    }
}

For some reason, with the prefix and match_phrase_prefix it seems like i cant add score boosters.

What i would like to achieve should look something like this:

"query": {
    "bool": {
        "should": [{
            "prefix": {
               "title": "נפצ"
               "score": 2
            }
                   },{
            "prefix": {
               "sub_title": "נפ"
               "score": 1
            }
                  }]
    }
}

[edited] Using boost should solve the issue. According to the documentation , something like that must work for you (although I haven't tried it on my own):

"query": {
    "bool": {
        "should": [{
            "prefix": {
               "title": {
                  "value": "נפצ",
                  "boost": 2.0
               }
            }},{
            "match_phrase_prefix": {
               "sub_title": {
                  "query": "נפצע קש",
                  "boost": 1.0
               }
            }
        }]
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM