5

我正在使用以下内容对 Elasticsearch 中具有“usernamesAssigned”属性的文档进行排序。usernamesAssigned 是一个字符串数组:

"sort": [
    {
        "_script": {
            "script": "doc["usernamesAssigned"].values.sort().join()",
            "type": "string",
            "lang": "js",
            "order": "asc"
        }
    }
]

我想知道是否有更有效的方法可以在不使用基于脚本的排序的情况下做到这一点?

4

1 回答 1

2

This is an old question, but I recently wandered across it while trying to solve the same problem...

According to the documentation:

Elasticsearch supports sorting by array or multi-valued fields. The mode option controls what array value is picked for sorting the document it belongs to.

So, you should be able to sort like this:

"sort" : [ {"usernamesAssigned" : {"order" : "asc", "mode" : "min"}} ]

This has been available since version 0.90.0.Beta1.

于 2015-12-29T23:40:28.390 回答