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

时间:2014-02-18 15:20:47

标签: sorting nested elasticsearch

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

  

根据所使用的sort_mode,在排序期间挑选最高(最大)或最低(最小)内部对象。

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

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

我希望按authors.last, authors.first排序,它会使用Reiter, Jordan进行排序?

1 个答案:

答案 0 :(得分:2)

不幸的是没有。

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

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

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