# What is search context?

**URL:** <https://discuss.elastic.co/t/what-is-search-context/74014>\
**Category:** Elasticsearch\
**Created:** [February 6, 2017, 7:02am UTC](https://discuss.elastic.co/t/what-is-search-context/74014 "2017-02-06T07:02:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Utkarsh\_Pyne](https://avatars.discourse-cdn.com/v4/letter/u/a587f6/32.png) [@Utkarsh\_Pyne](https://discuss.elastic.co/u/Utkarsh_Pyne)\
**Post date:** [February 6, 2017, 7:02am UTC](https://discuss.elastic.co/t/what-is-search-context/74014/1 "2017-02-06T07:02:20Z")

</div>

What is search context and how and when is it created ? Is there a good number beyond which if the number of search contexts go, it can be alarming ?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 6, 2017, 9:31am UTC](https://discuss.elastic.co/t/what-is-search-context/74014/2 "2017-02-06T09:31:43Z")

</div>

SearchContext is the state that is maintained for the duration of a search operation on a shard. The more concurrent search operations you have the more SearchContext objects are active at any one time.

---

<div class="post-metadata">

**Author:** ![Utkarsh\_Pyne](https://avatars.discourse-cdn.com/v4/letter/u/a587f6/32.png) [@Utkarsh\_Pyne](https://discuss.elastic.co/u/Utkarsh_Pyne)\
**Post date:** [February 6, 2017, 12:06pm UTC](https://discuss.elastic.co/t/what-is-search-context/74014/3 "2017-02-06T12:06:57Z")

</div>

Is there a way to estimate the heap size taken up by SearchContext objects or maybe an API that outputs the amount of space taken up by these objects.

We have around 100-200 SearchContexts objects as shown by the NodeStats API, was wondering how much they are contributing to my cluster's heap space. During a peak we even saw around 1500 open search context, was not sure if this was too much or normal ?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 6, 2017, 12:11pm UTC](https://discuss.elastic.co/t/what-is-search-context/74014/4 "2017-02-06T12:11:09Z")

</div>

> [@Utkarsh\_Pyne](#):
>
> was wondering how much they are contributing to my cluster's heap space.

These aren't normally a concern - other interim state like aggregation buckets tend to be the main cause for worry.

---

<div class="post-metadata">

**Author:** ![Utkarsh\_Pyne](https://avatars.discourse-cdn.com/v4/letter/u/a587f6/32.png) [@Utkarsh\_Pyne](https://discuss.elastic.co/u/Utkarsh_Pyne)\
**Post date:** [February 6, 2017, 12:18pm UTC](https://discuss.elastic.co/t/what-is-search-context/74014/5 "2017-02-06T12:18:29Z")

</div>

> [@Mark\_Harwood](#):
>
> aggregation buckets

By aggregation buckets are you referring to field-data cache or something else ?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 6, 2017, 12:27pm UTC](https://discuss.elastic.co/t/what-is-search-context/74014/6 "2017-02-06T12:27:45Z")

</div>

field-data cache is a fixed-cost for all aggs (now largely superseded by doc values). It's where we lookup values.

Aggregation buckets are a per-request cost containing the interim state e.g. calculating the movie counts for _all_ actors before returning the substantially trimmed final result of "top 10 movie stars".

---

<div class="post-metadata">

**Author:** ![Utkarsh\_Pyne](https://avatars.discourse-cdn.com/v4/letter/u/a587f6/32.png) [@Utkarsh\_Pyne](https://discuss.elastic.co/u/Utkarsh_Pyne)\
**Post date:** [February 6, 2017, 12:43pm UTC](https://discuss.elastic.co/t/what-is-search-context/74014/7 "2017-02-06T12:43:01Z")

</div>

> [@Mark\_Harwood](#):
>
> Aggregation buckets are a per-request cost containing the interim state e.g. calculating the movie counts for all actors before returning the substantially trimmed final result of "top 10 movie stars".

Is there an API where we can see the portion of the heap consumed by these buckets, we have a mismatch wherein we see that total JVM heap consumed is not sum of field-data + filter-cache + ID\_cache + Shard Query Cache + Segment in Memory + Merges in Memory + everything that shows up in the "indices" bucket in Node Stats output.

---

<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:** [March 6, 2017, 12:43pm UTC](https://discuss.elastic.co/t/what-is-search-context/74014/8 "2017-03-06T12:43:02Z")

</div>

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