# Sorting on nested field and then apply aggregation

**URL:** <https://discuss.elastic.co/t/sorting-on-nested-field-and-then-apply-aggregation/309078>\
**Category:** Elasticsearch\
**Created:** [July 7, 2022, 6:34am UTC](https://discuss.elastic.co/t/sorting-on-nested-field-and-then-apply-aggregation/309078 "2022-07-07T06:34:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aryamansingh888](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@aryamansingh888](https://discuss.elastic.co/u/aryamansingh888)\
**Post date:** [July 7, 2022, 6:34am UTC](https://discuss.elastic.co/t/sorting-on-nested-field-and-then-apply-aggregation/309078/1 "2022-07-07T06:34:19Z")

</div>

"visitor\_data": [

```
        {

          "end_date": "2021-06-08",

          "pre_status": "1",

          "evisitor": true,

          "edition_id": "644659",

          "flag": "1",

          "event_functionality": "open",

          "completed_on": "1535519400",

          "interest_date": "1535519400",

          "visitor_score": "10",

          "is_verified": true,

          "visitor_published": "1",

          "event_id": "9",

          "event_published": "1",

          "event_type": "1",

          "interest": 1000,

          "start_date": "2020-06-06"

        },

        {

          "end_date": "2021-12-17",

          "evisitor": true,

          "edition_id": "747339",

          "flag": "1",

          "event_functionality": "draft",

          "completed_on": "1579179872",

          "interest_date": "1579179872",

          "is_verified": true,

          "visitor_published": "1",

          "event_id": "9",

          "event_published": "1",

          "event_type": "1",

          "interest": 1000,

          "start_date": "2021-11-17"

        },

        {

          "end_date": "2019-07-28",

          "evisitor": true,

          "edition_id": "716029",

          "flag": "1",

          "event_functionality": "draft",

          "completed_on": "1579514911",

          "interest_date": "1579514911",

          "is_verified": true,

          "visitor_published": "1",

          "event_id": "333905",

          "event_published": "1",

          "event_type": "1",

          "interest": 1000,

          "start_date": "2019-07-19"

        }

```

]

Hi,

In above example data. visitor\_data is nested key. which store event details in which user visited. Now,

I want to fetch all unique event\_id in which user visited with order by end\_date.

---

<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:** [August 4, 2022, 6:35am UTC](https://discuss.elastic.co/t/sorting-on-nested-field-and-then-apply-aggregation/309078/2 "2022-08-04T06:35:03Z")

</div>

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