# Why my term query slow?

**URL:** <https://discuss.elastic.co/t/why-my-term-query-slow/173589>\
**Category:** Elasticsearch\
**Created:** [March 23, 2019, 9:56am UTC](https://discuss.elastic.co/t/why-my-term-query-slow/173589 "2019-03-23T09:56:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yc1024](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yc1024/32/42644_2.png) [@yc1024](https://discuss.elastic.co/u/yc1024)\
**Post date:** [March 23, 2019, 9:56am UTC](https://discuss.elastic.co/t/why-my-term-query-slow/173589/1 "2019-03-23T09:56:01Z")

</div>

I configure the following parameter, but my query is still very slow.  
"index.store.preload": ["nvd", "dvd", "tim", "doc", "dim"]

my dsl as follw:  
{"query": { "bool":{"filter":{"bool":{"must":[{"term" : { "ALL" :"hvc" }},{"term" : { "ALL" :"vcr" }},{"term" : { "ALL" :"crr" }},{"term" : { "ALL" :"rrt" }},{"term" : { "ALL" :"rtx" }},{"term" : { "ALL" :"txp" }},{"term" : { "ALL" :"xph" }},{"term" : { "ALL" :"phj" }},{"term" : { "ALL" :"hjb" }},{"term" : { "ALL" :"jby" }},{"term" : { "ALL" :"byl" }},{"term" : { "ALL" :"yls" }},{"term" : { "ALL" :"lsu" }},{"term" : { "ALL" :"sun" }},{"term" : { "ALL" :"unq" }},{"term" : { "ALL" :"nqs" }},{"term" : { "ALL" :"qsv" }},{"term" : { "ALL" :"svd" }},{"term" : { "ALL" :"vdl" }},{"term" : { "ALL" :"dlr" }},{"term" : { "ALL" :"lru" }},{"term" : { "ALL" :"rul" }},{"term" : { "ALL" :"ulv" }},{"term" : { "ALL" :"lvl" }},{"term" : { "ALL" :"vlj" }},{"term" : { "ALL" :"ljv" }},{"term" : { "ALL" :"jvl" }},{"term" : { "ALL" :"vlq" }}]}}}}}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 23, 2019, 1:26pm UTC](https://discuss.elastic.co/t/why-my-term-query-slow/173589/2 "2019-03-23T13:26:38Z")

</div>

What is the response ?

---

<div class="post-metadata">

**Author:** ![yc1024](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yc1024/32/42644_2.png) [@yc1024](https://discuss.elastic.co/u/yc1024)\
**Post date:** [March 25, 2019, 2:44am UTC](https://discuss.elastic.co/t/why-my-term-query-slow/173589/3 "2019-03-25T02:44:41Z")

</div>

@dadoonet thanks for your reply.

the response is :

```auto
{
  "took" : 19292,
  "timed_out" : false,
  "_shards" : {
    "total" : 10,
    "successful" : 10,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.0,

```

I found this comment in the elasticsearch6.1.3‘s source code about `index.store.preload`

```auto
   /** On which extensions to load data into the file-system cache upon opening of files.
     * This only works with the mmap directory, and even in that case is still
     * best-effort only. */

```

my `index.store.type` is `niofs`, maybe I mismatched this parameter.

---

<div class="post-metadata">

**Author:** ![Lumaraf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lumaraf/32/50639_2.png) [@Lumaraf](https://discuss.elastic.co/u/Lumaraf)\
**Post date:** [March 25, 2019, 11:50am UTC](https://discuss.elastic.co/t/why-my-term-query-slow/173589/4 "2019-03-25T11:50:38Z")

</div>

How big is the index and what are the specs of your servers? Could you also post a profile of your query? [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-profile.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-profile.html)

I guess that all the terms are quite common which should result in a high nextdoc count in the profiler output which would explain what is taking so long.

---

<div class="post-metadata">

**Author:** ![yc1024](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yc1024/32/42644_2.png) [@yc1024](https://discuss.elastic.co/u/yc1024)\
**Post date:** [March 26, 2019, 5:13am UTC](https://discuss.elastic.co/t/why-my-term-query-slow/173589/5 "2019-03-26T05:13:09Z")

</div>

Hi @Lumaraf ,the nextdoc costs 82.8% of the time, what optimization can i do?  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/8/18fde36cd17677c38de62156ae13839f8461a5d1.png)

---

<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:** [April 23, 2019, 5:26am UTC](https://discuss.elastic.co/t/why-my-term-query-slow/173589/6 "2019-04-23T05:26:17Z")

</div>

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