Link Search Menu Expand Document Documentation Menu

评分脚本过滤器

评分脚本过滤器首先过滤文档,然后对结果执行暴力精确 k-NN 搜索。例如,以下查询会搜索评分在 8 到 10(含)之间且提供停车位的酒店,然后执行 k-NN 搜索以返回距离指定 location 最近的 3 家酒店。

POST /hotels-index/_search
{
  "size": 3,
  "query": {
    "script_score": {
      "query": {
        "bool": {
          "filter": {
            "bool": {
              "must": [
                {
                  "range": {
                    "rating": {
                      "gte": 8,
                      "lte": 10
                    }
                  }
                },
                {
                  "term": {
                    "parking": "true"
                  }
                }
              ]
            }
          }
        }
      },
      "script": {
        "source": "knn_score",
        "lang": "knn",
        "params": {
          "field": "location",
          "query_value": [
            5.0,
            4.0
          ],
          "space_type": "l2"
        }
      }
    }
  }
}

剩余 350 字符

有问题?

想做贡献?