# Bool term filter slow

**URL:** <https://discuss.elastic.co/t/bool-term-filter-slow/104112>\
**Category:** Elasticsearch\
**Created:** [October 16, 2017, 3:42pm UTC](https://discuss.elastic.co/t/bool-term-filter-slow/104112 "2017-10-16T15:42:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Sedeno](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_sedeno/32/37347_2.png) [@David\_Sedeno](https://discuss.elastic.co/u/David_Sedeno)\
**Post date:** [October 16, 2017, 3:42pm UTC](https://discuss.elastic.co/t/bool-term-filter-slow/104112/1 "2017-10-16T15:42:08Z")

</div>

I have a bool query with a filter that took ~260ms. If I simply remove the filter (just a term filter) the query take ~60ms.

The index has around 16Mill of docs and the filters takes out around 1Mill. it's possible that the filter doesn't use the cache so it's so slow ?

I have done a \_profile to the query:

```
   "type": "TermQuery",
    "description": "situacion:x",
     "time": "219.7595780ms",
      "time_in_nanos": 219759578,
            "breakdown": {
               "score": 0,
                "build_scorer_count": 66,
                "match_count": 0,
                "create_weight": 1560,
                "next_doc": 216418252,
                "match": 0,
                "create_weight_count": 1,
                "next_doc_count": 2810343,
                "score_count": 0,
                "build_scorer": 529356,
                "advance": 0,
                "advance_count": 0
            }

```

the more expensive is the next\_doc but I really doesn't known what this means and how to optimize it.

---

<div class="post-metadata">

**Author:** ![David\_Sedeno](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_sedeno/32/37347_2.png) [@David\_Sedeno](https://discuss.elastic.co/u/David_Sedeno)\
**Post date:** [October 17, 2017, 7:20am UTC](https://discuss.elastic.co/t/bool-term-filter-slow/104112/2 "2017-10-17T07:20:25Z")

</div>

If I put the filter in a post\_filter top field, the query run fast:

```auto
   "query": { 
      "bool": {... 
           }
   }, 
   "post_filter": {
      "term": { ... } 
    }

```

Is this the way to go?

---

<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:** [November 14, 2017, 7:20am UTC](https://discuss.elastic.co/t/bool-term-filter-slow/104112/3 "2017-11-14T07:20:35Z")

</div>

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