# Sort using nested\_filter internal implementation and performance concerns

**URL:** <https://discuss.elastic.co/t/sort-using-nested-filter-internal-implementation-and-performance-concerns/18078>\
**Category:** Elasticsearch\
**Created:** [June 12, 2014, 7:40pm UTC](https://discuss.elastic.co/t/sort-using-nested-filter-internal-implementation-and-performance-concerns/18078 "2014-06-12T19:40:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erich\_Lin\_2](https://avatars.discourse-cdn.com/v4/letter/e/b38774/32.png) [@Erich\_Lin\_2](https://discuss.elastic.co/u/Erich_Lin_2)\
**Post date:** [June 12, 2014, 7:40pm UTC](https://discuss.elastic.co/t/sort-using-nested-filter-internal-implementation-and-performance-concerns/18078/1 "2014-06-12T19:40:56Z")

</div>

The description for nested\_filter is:

"Common case is to repeat the query / filter inside the nested filter or  
query. "

If my search involves something like:

GET /library/book/\_search  
{  
"query": {  
"nested": {  
"path": "prices",  
"score\_mode": "total",

- 

```
 "query": {*

```

- 

```
   "match": {*

```

- 

```
     "region": "cities"*
  }
}

```

}  
},  
"sort": [  
{  
"price": {  
"mode": "avg",  
"order": "asc",  
"nested\_path": "prices",  
"nested\_filter": {
- 

```
     "query": {*

```

- 

```
       "match": {*

```

- 

```
         "region": "cities"*
      }
    }
  }
}

```

},  
"\_score"  
]  
}

If you run a sort on a nested field and use the nested\_filter, how is that  
implemented internally?

Secondly, are there any performance concerns or gotchas?

In this case, the query is repeated for the hits and for the sort. How much  
of a concern is this? What if there were multiple sort fields used and each  
sort field has query repeated?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5888ee5d-1648-4f6c-8e60-62c5539a8b5b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5888ee5d-1648-4f6c-8e60-62c5539a8b5b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:22am UTC](https://discuss.elastic.co/t/sort-using-nested-filter-internal-implementation-and-performance-concerns/18078/2 "2017-07-06T01:22:56Z")

</div>

Closed on July 6, 2017, 1:22am UTC


