# Inner hits returned in reversed order in ES7 as compared to ES6

**URL:** <https://discuss.elastic.co/t/inner-hits-returned-in-reversed-order-in-es7-as-compared-to-es6/200093>\
**Category:** Elasticsearch\
**Created:** [September 18, 2019, 10:41pm UTC](https://discuss.elastic.co/t/inner-hits-returned-in-reversed-order-in-es7-as-compared-to-es6/200093 "2019-09-18T22:41:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarthakn](https://avatars.discourse-cdn.com/v4/letter/s/a8b319/32.png) [@sarthakn](https://discuss.elastic.co/u/sarthakn)\
**Post date:** [September 18, 2019, 10:41pm UTC](https://discuss.elastic.co/t/inner-hits-returned-in-reversed-order-in-es7-as-compared-to-es6/200093/1 "2019-09-18T22:41:23Z")

</div>

Hello, while migrating to ES7 we noticed that the inner hits are returned in a different order as compared to ES6. For e.g., consider a document that contains a nested field with 4 entries say 1,2,3 and 4. The nested fields returned by ES6 are in order 4,3 and 2 while ES7 returns 1,2 and 3. Is this change intentional ? Is there any way to get the previous behavior ?

To replicate:

> **Create index with this mapping (remove the type for ES7)**
>
> {  
> "mappings": {  
> "\_doc" : {  
> "dynamic": "strict",  
> "properties": {  
> "name": {  
> "type": "text"  
> },  
> "nested\_field": {  
> "type": "nested",  
> "properties": {  
> "id": {  
> "type": "integer"  
> }  
> }  
> }  
> }  
> }  
> }  
> }

> **Insert a document:**
>
> {  
> "name": "test",  
> "nested\_field": [  
> {  
> "id": 1  
> },  
> {  
> "id": 2  
> },  
> {  
> "id": 3  
> },  
> {  
> "id": 4  
> }  
> ]  
> }

> **Query the index:**
>
> {  
> "query": {  
> "bool": {  
> "filter": [  
> {  
> "nested": {  
> "path": "nested\_field",  
> "query": {  
> "match\_all": {}  
> },  
> "inner\_hits": {}  
> }  
> }  
> ]  
> }  
> }  
> }

> **Inner hits returned in ES6:**
>
> "inner\_hits": {  
> "nested\_field": {  
> "hits": {  
> "total": 4,  
> "max\_score": 1.0,  
> "hits": [  
> {  
> "\_index": "test\_index",  
> "\_type": "\_doc",  
> "\_id": "1",  
> "\_nested": {  
> "field": "nested\_field",  
> "offset": 3  
> },  
> "\_score": 1.0,  
> "\_source": {  
> "id": 4  
> }  
> },  
> {  
> "\_index": "test\_index",  
> "\_type": "\_doc",  
> "\_id": "1",  
> "\_nested": {  
> "field": "nested\_field",  
> "offset": 2  
> },  
> "\_score": 1.0,  
> "\_source": {  
> "id": 3  
> }  
> },  
> {  
> "\_index": "test\_index",  
> "\_type": "\_doc",  
> "\_id": "1",  
> "\_nested": {  
> "field": "nested\_field",  
> "offset": 1  
> },  
> "\_score": 1.0,  
> "\_source": {  
> "id": 2  
> }  
> }  
> ]  
> }  
> }  
> }

> **Inner hits returned in ES7:**
>
> "inner\_hits": {  
> "nested\_field": {  
> "hits": {  
> "total": {  
> "value": 4,  
> "relation": "eq"  
> },  
> "max\_score": 1.0,  
> "hits": [  
> {  
> "\_index": "test\_index",  
> "\_type": "\_doc",  
> "\_id": "1",  
> "\_nested": {  
> "field": "nested\_field",  
> "offset": 0  
> },  
> "\_score": 1.0,  
> "\_source": {  
> "id": 1  
> }  
> },  
> {  
> "\_index": "test\_index",  
> "\_type": "\_doc",  
> "\_id": "1",  
> "\_nested": {  
> "field": "nested\_field",  
> "offset": 1  
> },  
> "\_score": 1.0,  
> "\_source": {  
> "id": 2  
> }  
> },  
> {  
> "\_index": "test\_index",  
> "\_type": "\_doc",  
> "\_id": "1",  
> "\_nested": {  
> "field": "nested\_field",  
> "offset": 2  
> },  
> "\_score": 1.0,  
> "\_source": {  
> "id": 3  
> }  
> }  
> ]  
> }  
> }  
> }

---

<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:** [October 16, 2019, 10:41pm UTC](https://discuss.elastic.co/t/inner-hits-returned-in-reversed-order-in-es7-as-compared-to-es6/200093/2 "2019-10-16T22:41:32Z")

</div>

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