基于响应中分数的弹性搜索查询

Elastic search query based on score in the response

当有多个记录与查询匹配时,我们可以查询 ES 以 return 只有一个在响应中得分最高的结果吗?

如果有任何示例查询,请告诉我。谢谢。

示例response/document:- 我使用类似搜索。 截至目前,我的服务记录低于 returns。

record1 - product1, value1, score=1.5 
record2 - product1, value2, score=1.4
record3 - product2, value1, score=1.7
record4 - product2, value2, score=0.8
record5 - product3, value1, score=1.2

我想要只有以下记录的结果,它将根据分数过滤产品。每个产品只有一条记录。

record1 - product1, value1, score=1.5
record3 - product2, value1, score=1.7
record5 - product3, value1, score=1.2

更多详情:- 创建了自定义分析器:-

"analysis": {

    "filter": {
        "autocomplete_filter": {
            "type": "edge_ngram",
            "min_gram": "1",
            "max_gram": "20"
        }
    },
    "analyzer": {
        "autocomplete": {
            "filter": [
                "autocomplete_filter"
            ],
            "type": "custom",
            "tokenizer": "keyword"
        }
    }

}

映射:-

"PRODUCT_ID": {

    "analyzer": "autocomplete",
    "type": "string"

}

查询:-

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "PRODUCT_ID": "CON-HSH-AS"
          }
        }
      ],
      "must_not": [],
      "should": []
    }
  },
  "from": 0,
  "size": 10,
  "sort": [],
  "aggs": {}
}

您可以查看top-hits aggregation。也许它会对您的用例有所帮助:)