# Help understanding innerhit performance

**URL:** <https://discuss.elastic.co/t/help-understanding-innerhit-performance/81226>\
**Category:** Elasticsearch\
**Created:** [April 4, 2017, 10:29pm UTC](https://discuss.elastic.co/t/help-understanding-innerhit-performance/81226 "2017-04-04T22:29:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hcliff](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hcliff](https://discuss.elastic.co/u/hcliff)\
**Post date:** [April 4, 2017, 10:29pm UTC](https://discuss.elastic.co/t/help-understanding-innerhit-performance/81226/1 "2017-04-04T22:29:11Z")

</div>

I have a parent/child relationship that queries very performantly but when retrieving innerhits falls over. Since I'm not returning the source and elastic has already done this computation to determine if there's a hit why does it matter?

```
POST browse/_search?request_cache=false
{
  "_source": {
    "excludes": [],
    "includes": [
      "resolvedName",
      "ll",
      "genre"
    ]
  },
  "from": 0,
  "query": {
    "bool": {
      "filter": [
        {
          "geo_bounding_box": {
            "ll": {
              "bottom_right": [
                -73.9544677734375,
                40.70979201243495
              ],
              "top_left": [
                -73.9599609375,
                40.71395582628603
              ]
            }
          }
        },
        {
          "type": {
            "value": "venues"
          }
        }
      ],
      "should": {
        "has_child": {
          "inner_hits": {
            "_source": false,
            "size": 1
          },
          "query": {
            "bool": {
              "filter": [
                {
                  "term": {
                    "published": true
                  }
                }
              ]
            }
          },
          "type": "events"
        }
      }
    }
  },
  "size": 1500
}

```

Takes 200-300ms on my es instance. Dropping the inner\_hits clause (but keeping the has\_child filter) reduces query time to about 13ms(!)

In the provided code I'm trying to pull back all venues in an area and annotate if they have an "event" at them. I can hack around this by sniffing the matched\_queries but that's a bit grim.

Thanks

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [April 7, 2017, 7:56am UTC](https://discuss.elastic.co/t/help-understanding-innerhit-performance/81226/2 "2017-04-07T07:56:55Z")

</div>

Inner hits are slow indeed. They need to run the query again on specific documents to check which children matched.

It is true that Elasticsearch already computed this information, but at the same time, there could be matches and it would require a lot of memory to keep track of this information for all matches.

---

<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:** [May 5, 2017, 8:00am UTC](https://discuss.elastic.co/t/help-understanding-innerhit-performance/81226/3 "2017-05-05T08:00:48Z")

</div>

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