Elasticsearch 按子文档中的字段排序

Ele*_*zer 6 elasticsearch

我的文件看起来像这样:

{
    "parent" : {
        "properties" : {
            "id": {
                "type" : "keyword"
            }
            "name" : {
                "type" : "keyword"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

和子文件:

{
    "child": {
        "_parent": {
            "type": "parent"
        },
        "_routing": {
            "required": true
        },
        "properties": {
            "child_id": {
                "type" : "keyword"
            },
            "child_name" : {
                 "type" : "keyword"
            },
            "child_time": {
                "type": "date"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如何按子项的子名称和最新的子时间对父文档进行排序?

Tob*_*ann 0

我无法解释细节,因为我还不明白它们,但我找到了这个解决方法:

https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-has-child-query.html#_sorting

相应的功能请求将提供一种按子文档值排序的显式方法,已关闭: https: //github.com/elastic/elasticsearch/issues/2917