2021年4月25日星期日

Elasticsearch dynamic choose query

When querying with the should command, I am wondering if there is a way to make only the responses of queries with higher scores come out.

I'm sorry I'm not good at English, please understand it. Let's assume I have such data

index

{    "mappings": {      "properties": {        "name": {          "type": "keyword"        }      }    }  }  

data

{    "_index" : "dismisstest",    "_type" : "_doc",    "_id" : "1",    "_score" : 1.0,    "_source" : {      "name" : "chul"    }  },  {    "_index" : "dismisstest",    "_type" : "_doc",    "_id" : "2",    "_score" : 1.0,    "_source" : {      "name" : "wedul"    }  }  

query (example..)

GET dismisstest/_search  {    "query": {      "bool": {        "should": [          {            "term": {              "name": {                "value": "wedul",                "boost": 2              }            }          },          {            "term": {              "name": {                "value": "chul",                "boost": 4              }            }          }        ]      }    }  }  

want result (Document using only wedul query)

{    "_index" : "dismisstest",    "_type" : "_doc",    "_id" : "2",    "_score" : 1.0,    "_source" : {      "name" : "wedul"    }  }  

The above query is a simple example, but I want to use only the query that returns the document with a high score among the two should queries. Is there any possible way??

https://stackoverflow.com/questions/67175904/elasticsearch-dynamic-choose-query April 20, 2021 at 05:12PM

没有评论:

发表评论