Sort using nested_filter internal implementation and performance concerns

(Erich Lin-2) #1

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"*

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
To view this discussion on the web visit
For more options, visit

(system) #2