Elasticsearch order by field in child document

I have documents that look like this:

{
    "parent" : {
        "properties" : {
            "id": {
                "type" : "keyword"
            }
            "name" : {
                "type" : "keyword"
            }
        }
    }
}

and child documents:

{
    "child": {
        "_parent": {
            "type": "parent"
        },
        "_routing": {
            "required": true
        },
        "properties": {
            "child_id": {
                "type" : "keyword"
            },
            "child_name" : {
                 "type" : "keyword"
            },
            "child_time": {
                "type": "date"
            }
        }
    }
}

How can I sort parent documents by child_name with the last child_time?

+4
source share
1 answer

I cannot explain the details because I still do not understand them, but I found this workaround:

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

The corresponding function request, which would provide an explicit way to sort by value for child documents, was closed: https://github.com/elastic/elasticsearch/issues/2917

0
source

Source: https://habr.com/ru/post/1666385/


All Articles