首页 > 解决方案 > Elasticsearch 动态选择查询

问题描述

使用 should 命令查询时,我想知道是否有办法只输出分数较高的查询的响应。

对不起,我英语不好,请理解。假设我有这样的数据

指数

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

数据

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

查询(例如..)

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

想要结果(仅使用 wedul 查询的文档)

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

上面的查询是一个简单的例子,但我只想使用返回两个应该查询中得分高的文档的查询。有什么办法吗??

标签: elasticsearch

解决方案



推荐阅读