在function_score搜索期间创建一个新字段

时间:2020-02-19 17:51:24

标签: elasticsearch scripting elasticsearch-query

我正在尝试使用function_score执行搜索,但是我想检查在function_score过滤期间匹配了哪些功能。

在此elasticsearch页面示例中。

GET /_search
{
    "query": {
        "function_score": {
          "query": { "match_all": {} },
          "boost": "5", 
          "functions": [
              {
                  "filter": { "match": { "test": "bar" } },
                  "random_score": {}, 
                  "weight": 23
              },
              {
                  "filter": { "match": { "test": "cat" } },
                  "weight": 42
              }
          ],
          "max_boost": 42,
          "score_mode": "max",
          "boost_mode": "multiply",
          "min_score" : 42
        }
    }
}

一旦获得结果,我怎么知道哪个结果来自哪个匹配项?例如,结果如下:

{
    "took": 11,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 30,
            "relation": "eq"
        },
        "max_score": 3,
        "hits": [
            {
                "_index": "my_index",
                "_type": "my_index",
                "_id": "2",
                "_score": 23,
                "_source": {
                    "id": 2,
                    "test": "It contains bar"
                }
            },
            {
                "_index": "my_index",
                "_type": "my_index",
                "_id": "2",
                "_score": 42,
                "_source": {
                    "id": 2,
                    "test": "It contains cat"
                }
            }
        ]
    }
}

我正在寻找“ script_fields”之类的东西。我想在搜索过程中ADD用新的field,告诉我该响应使用哪个过滤器。因此,当我浏览这些命中信息时,我可以看到使用了哪些功能分数来产生结果。

0 个答案:

没有答案