按嵌套类型数组中的第一个元素排序

根据这个链接
describing the addition of sorting by nested fields to ElasticSearch

Either the highest (max) or lowest (min) inner object is picked for during sorting depending on the sort_mode being used.

有没有办法,它使用数组的第一个值而不是使用最高或最低值?例如,如果记录如下所示:

{
    "title": "Blah blah blah",
    "authors": [
        {
            "last": "Reiter",
            "first": "Jordan",
        },
        {
            "last": "Jim",
            "first": "Lee",
        }
    ]
}

我想按authors.last,authors.first对给定记录进行排序,它会使用Reiter,Jordan进行排序吗?

最佳答案 不幸的是.

我建议在父文档中存储要排序的作者,即

title: "Blah blah"
sortByAuthor: "Jordan Reiter"
authors: [
    ...
]

您可以使用脚本来逃避当前的结构,但是您将在内存中加载更多的内容.

点赞