Elasticsearch 基于多值字段中的元素排序

Elasticsearch sort based on element in multivalue field

是否可以根据多值字段中存在的元素进行排序?

示例:

a)  document with "111" 

put test/test/1
{
   "bit_position" : [
        1,
        2,
        3
    ]
}

b) document with 010
put test/test/2
{
   "bit_position": [
      2
   ]
}

基于 "bit_position" = 3 的排序应该 return 记录 a,然后记录 b。

我读到过这可能是嵌套字段,但在 bit_position 未嵌套时找不到任何相关信息。

我发现了这个问题:Sorting by value in multivalued field in elasticsearch 但还没有人回答。

谢谢

我使用 function_score 解决了这个问题:

POST test/_search
{
    "query": {
        "function_score": {
            "match_all": {},
            "functions": [
                {
                    "filter": {
                        "terms": {
                           "bit_position": [
                              1,
                              3
                           ]
                        }
                    },
                    "weight": 2
                }
            ],
            "score_mode": "multiply"
        }
    }
}