# Displaying documents in result multiple times with sorting

**URL:** <https://discuss.elastic.co/t/displaying-documents-in-result-multiple-times-with-sorting/116264>\
**Category:** Elasticsearch\
**Created:** [January 19, 2018, 3:14pm UTC](https://discuss.elastic.co/t/displaying-documents-in-result-multiple-times-with-sorting/116264 "2018-01-19T15:14:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pszegvari](https://avatars.discourse-cdn.com/v4/letter/p/edb3f5/32.png) [@pszegvari](https://discuss.elastic.co/u/pszegvari)\
**Post date:** [January 19, 2018, 3:14pm UTC](https://discuss.elastic.co/t/displaying-documents-in-result-multiple-times-with-sorting/116264/1 "2018-01-19T15:14:03Z")

</div>

Let's say that a nested document about a person can store data of type birthData, deathData, etc. We want to get ES documents sorted by _[MONTH-DAY DESC], [YEAR ASC]_.

Filtering and sorting by a single event type is a piece of cake, but what if I want to sort by multiple event dates and display a document as many times as there are dates inside? As we have several millions of docs, and multiple event types, result manipulaton on application server would be a no-go

Short example:

```
{
        "id": "ID1",
        "fullName": "John Smith",
        "eventsData": [
          {
            "event_data_type": "BD",
            "event_date": "1971-12-30T00:00:00Z",
          },
          {
            "event_data_type": "DD",
            "event_date": "2013-02-11T00:00:00Z",
          }
        ]
    },
    {
        "id": "ID2",
        "fullName": "Jake Smith",
        "eventsData": [
          {
            "event_data_type": "BD",
            "event_date": "1965-02-02T00:00:00Z",
          },
          {
            "event_data_type": "DD",
            "event_date": "2011-12-30T00:00:00Z",
          }
        ]
    }

```

The printed results with relevant data would be:

```
   ID1, BD, 1971-12-30
   ID2, DD, 2011-12-30
   ID1, DD, 2013-02-11
   ID2, BD, 1965-02-02

```

So if a document has _n_ events, then it is displayed _n_ times.

Can you offer any elastic search solution for this problem? What feature should we use?

---

<div class="post-metadata">

**Author:** ![s1monw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/s1monw/32/3637_2.png) [@s1monw](https://discuss.elastic.co/u/s1monw)\
**Post date:** [January 26, 2018, 11:32am UTC](https://discuss.elastic.co/t/displaying-documents-in-result-multiple-times-with-sorting/116264/2 "2018-01-26T11:32:06Z")

</div>

you have to index each event as an individual document to make that happen IMO

---

<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:** [February 23, 2018, 11:32am UTC](https://discuss.elastic.co/t/displaying-documents-in-result-multiple-times-with-sorting/116264/3 "2018-02-23T11:32:11Z")

</div>

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