Sorting nested array per match criteria


#1

Hi everyone,

Let's suppose I have the following document:

{
    "name": "Audi",
    "photos": [{
            "color": "blue ",
            "url": "www.audi.com/blue.jpg"
        }, {
            "url": "www.audi.com/black.jpg"
            "color": "black"
        }, {
            "url": "www.audi.com/green.jpg"
            "color": "green"
        }
    ]
}

I would like to have the following result:

{
    "name": "Audi",
    "photos": [{
            "url": "www.audi.com/green.jpg"
            "color": "green"
        }, {
            "color": "blue ",
            "url": "www.audi.com/blue.jpg"
        }, {
            "url": "www.audi.com/black.jpg"
            "color": "black"
        }
    ]
}

Is it possible only to sort "photos" nested object that is to display within the nested object the object that has green color as the first?

Actually, this is the same question as a guy asked some time ago, so I think it would be good to have answer as soon as possible.
https://discuss.elastic.co/t/sort-nested-array-according-to-match-on-a-multi-match-query/59375


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.