# Sorting nested array per match criteria

**URL:** <https://discuss.elastic.co/t/sorting-nested-array-per-match-criteria/96060>\
**Category:** Elasticsearch\
**Created:** [August 7, 2017, 8:27am UTC](https://discuss.elastic.co/t/sorting-nested-array-per-match-criteria/96060 "2017-08-07T08:27:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![icebreaker](https://avatars.discourse-cdn.com/v4/letter/i/b782af/32.png) [@icebreaker](https://discuss.elastic.co/u/icebreaker)\
**Post date:** [August 7, 2017, 8:27am UTC](https://discuss.elastic.co/t/sorting-nested-array-per-match-criteria/96060/1 "2017-08-07T08:27:55Z")

</div>

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](https://discuss.elastic.co/t/sort-nested-array-according-to-match-on-a-multi-match-query/59375)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 4, 2017, 8:28am UTC](https://discuss.elastic.co/t/sorting-nested-array-per-match-criteria/96060/2 "2017-09-04T08:28:14Z")

</div>

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