# Return array's elements as separate entities in result and sort them per whole query

**URL:** <https://discuss.elastic.co/t/return-arrays-elements-as-separate-entities-in-result-and-sort-them-per-whole-query/143835>\
**Category:** Elasticsearch\
**Created:** [August 10, 2018, 8:43am UTC](https://discuss.elastic.co/t/return-arrays-elements-as-separate-entities-in-result-and-sort-them-per-whole-query/143835 "2018-08-10T08:43:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maksym.zhokha](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@maksym.zhokha](https://discuss.elastic.co/u/maksym.zhokha)\
**Post date:** [August 10, 2018, 8:43am UTC](https://discuss.elastic.co/t/return-arrays-elements-as-separate-entities-in-result-and-sort-them-per-whole-query/143835/1 "2018-08-10T08:43:27Z")

</div>

Hi. I have next mapping for index documents:

```auto
{
    "mappings": {
        "domain": {
            "properties": {
                "placementid": {
                    "include_in_all": true,
                    "type": "keyword"
                },
                "domain": {
                    "properties": {
                        "name": {
                            "include_in_all": true,
                            "type": "keyword"
                        }
                    }
                }
            }
        }
    }
}

```

So each domainset can have up to 500 elements in domain array. E.g. next there are two documents in the index.

```auto
[
    {
        "_source": {
            "placementid": "5b4f11a1379e37000192a14c",
            "domain": [
                {
                    "name": "test.example.com"
                },
                {
                    "name": "maks.example.com"
                }
            ]
        }
    },
    {
        "_source": {
            "placementid": "5b4f11a1379e37000192a14d",
            "domain": [
                {
                    "name": "alpha.example.com"
                },
                {
                    "name": "zet.example.com"
                }
            ]
        }
    }
]

```

Using search I need to have domain.name's to be returned as separate entries in result set to be able to sort them globally (not in scope of main document). So that searching by `domain.name:exmple.com` and sorting in ascenging order I would have next result:  
[alpha.example.com](http://alpha.example.com)  
[maks.example.com](http://maks.example.com)  
[test.example.com](http://test.example.com)  
[zet.example.com](http://zet.example.com)

Is it able to have such search in current index structure? If yes, could someone show the search example for this case?

---

<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 7, 2018, 8:43am UTC](https://discuss.elastic.co/t/return-arrays-elements-as-separate-entities-in-result-and-sort-them-per-whole-query/143835/2 "2018-09-07T08:43:36Z")

</div>

Closed on September 7, 2018, 8:43am UTC

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