# Sort seems to be ignored when filter contains a query on parent field

**URL:** <https://discuss.elastic.co/t/sort-seems-to-be-ignored-when-filter-contains-a-query-on-parent-field/88934>\
**Category:** Elasticsearch\
**Created:** [June 10, 2017, 9:55pm UTC](https://discuss.elastic.co/t/sort-seems-to-be-ignored-when-filter-contains-a-query-on-parent-field/88934 "2017-06-10T21:55:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pieterdt](https://avatars.discourse-cdn.com/v4/letter/p/87869e/32.png) [@pieterdt](https://discuss.elastic.co/u/pieterdt)\
**Post date:** [June 10, 2017, 9:55pm UTC](https://discuss.elastic.co/t/sort-seems-to-be-ignored-when-filter-contains-a-query-on-parent-field/88934/1 "2017-06-10T21:55:36Z")

</div>

Hi,

I have the following query:  
{  
"query": {  
"bool": {  
"must": {  
"has\_parent": {  
"type": "premises",  
"score\_mode": "score",  
"query": {  
"bool": {  
"must": {  
"match": {  
"street": {  
"query": "Generaal jacques",  
"minimum\_should\_match": "70%"  
}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"term": {  
"backyard": "S"  
}  
},  
{  
"term": {  
"status\_published": 1  
}  
},  
{  
"term": {  
"status\_visible": 1  
}  
},  
{  
"term": {  
"status\_approved": 1  
}  
}  
]  
}  
}  
}  
}  
}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"range": {  
"rent\_basic": {  
"gte": "200",  
"lte": "600"  
}  
}  
},  
{  
"nested": {  
"path": "period",  
"score\_mode": "none",  
"query": {  
"constant\_score": {  
"filter": {  
"bool": {  
"must": [  
{  
"term": {  
"period.available": 1  
}  
},  
{  
"range": {  
"period.start": {  
"lte": 1505433601  
}  
}  
},  
{  
"range": {  
"period.end": {  
"gte": 1497129105  
}  
}  
}  
]  
}  
}  
}  
}  
}  
},  
{  
"term": {  
"status\_published": 1  
}  
},  
{  
"term": {  
"status\_visible": 1  
}  
},  
{  
"term": {  
"status\_approved": 1  
}  
}  
]  
}  
}  
}  
}  
},  
"sort": [  
"\_score",  
{  
"surface\_area": "desc"  
}  
],  
"size": 10,  
"\_source": false  
}

The sort seems to be completely ignored, and I can't figure out why, as it sorts on a field of the child which we are querying. In short: the query looks for rooms that match certain criteria (filter) and for which the parent (the premises in which the room is housed) address matches the search term.

Any idea what could cause this? Or how should I understand this? Are there solutions?

Kind regards

pieter

---

<div class="post-metadata">

**Author:** ![pieterdt](https://avatars.discourse-cdn.com/v4/letter/p/87869e/32.png) [@pieterdt](https://discuss.elastic.co/u/pieterdt)\
**Post date:** [June 10, 2017, 10:38pm UTC](https://discuss.elastic.co/t/sort-seems-to-be-ignored-when-filter-contains-a-query-on-parent-field/88934/2 "2017-06-10T22:38:09Z")

</div>

ok, some stupid, obvious mistake could be the sort on \_score. However, even when removing that, and purely sorting on surface area doesn't seem to work.

In case you wonder (some stuff seems to be defined differently these days), my query is written voor ES 2.3

Kind regards

Pieter

---

<div class="post-metadata">

**Author:** ![pieterdt](https://avatars.discourse-cdn.com/v4/letter/p/87869e/32.png) [@pieterdt](https://discuss.elastic.co/u/pieterdt)\
**Post date:** [June 10, 2017, 10:59pm UTC](https://discuss.elastic.co/t/sort-seems-to-be-ignored-when-filter-contains-a-query-on-parent-field/88934/3 "2017-06-10T22:59:19Z")

</div>

Found out that when adding the sort to the url as a query string parameter, it works!

---

<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:** [July 8, 2017, 11:00pm UTC](https://discuss.elastic.co/t/sort-seems-to-be-ignored-when-filter-contains-a-query-on-parent-field/88934/4 "2017-07-08T23:00:12Z")

</div>

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