# Query performance issue with the very first one

**URL:** <https://discuss.elastic.co/t/query-performance-issue-with-the-very-first-one/219418>\
**Category:** Elasticsearch\
**Created:** [February 14, 2020, 4:50pm UTC](https://discuss.elastic.co/t/query-performance-issue-with-the-very-first-one/219418 "2020-02-14T16:50:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anto89](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@Anto89](https://discuss.elastic.co/u/Anto89)\
**Post date:** [February 14, 2020, 4:50pm UTC](https://discuss.elastic.co/t/query-performance-issue-with-the-very-first-one/219418/1 "2020-02-14T16:50:55Z")

</div>

The first time a query (classic full text query with a filter and a sort) is ran, it takes about 15-20s to get the result. It takes only few milliseconds for the next tries. Could anybody give me some explanations about the reason ? And how could I solve this and have a decent response time ?

Here is the configuration we have :  
ES version 6.2.3  
5 nodes (5 data nodes)  
1 index with 2P Shards / 2R - 900 000 docs (35GB)  
1 index with 1P Shard / 2R - 13 000 000 docs (10GB)  
2 CPUs / node with 8GB RAM

Thanks

---

<div class="post-metadata">

**Author:** ![rameshkr1994](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshkr1994/32/59029_2.png) [@rameshkr1994](https://discuss.elastic.co/u/rameshkr1994)\
**Post date:** [February 17, 2020, 8:30am UTC](https://discuss.elastic.co/t/query-performance-issue-with-the-very-first-one/219418/2 "2020-02-17T08:30:12Z")

</div>

Hi @Anto89.

welcome.

could you please explain about Elastic Qyery?what query running ?

Thanks  
HadoopHelp

---

<div class="post-metadata">

**Author:** ![Anto89](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@Anto89](https://discuss.elastic.co/u/Anto89)\
**Post date:** [February 17, 2020, 1:15pm UTC](https://discuss.elastic.co/t/query-performance-issue-with-the-very-first-one/219418/3 "2020-02-17T13:15:53Z")

</div>

Hi and thanks for your reply !

You'll find the kind of request we have to run at the bottom. I know the size of results I want to return is pretty big but by now I'm stuck with this behaviour. Basically what I need is to retrieve all ids of matching documents.

Before that there was another design where documents were splitted accross many indices (several thousand). We had issues when indexing but search was very fast.

```
POST index-name/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "NODE": "idNode"
          }
        }
      ],
      "should": [
        {
          "simple_query_string": {
            "query": "*",
            "fields": [
              "TITLE",
              "CONDITIONS",
              "CONTENT",
              "REFERENCE^5",
              "COMMENTS",
              "SUMMARY"
            ]
          }
        },
        {
          "match": {
            "NUMBER": {
              "operator": "or",
              "query": "*",
              "boost": 5
            }
          }
        }
      ],
      "minimum_should_match": 1
    }
  },
  "post_filter": {
    "bool": {
      "must": []
    }
  },
  "sort": [],
  "from": 0,
  "size": 10000,
  "_source": false
}
```

---

<div class="post-metadata">

**Author:** ![rameshkr1994](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshkr1994/32/59029_2.png) [@rameshkr1994](https://discuss.elastic.co/u/rameshkr1994)\
**Post date:** [February 17, 2020, 2:19pm UTC](https://discuss.elastic.co/t/query-performance-issue-with-the-very-first-one/219418/4 "2020-02-17T14:19:37Z")

</div>

Hi @Anto89.

Please try to use the combination of must and should with term condition as below.may be it will give you more faster result.  
` "query" : { "bool" : { "should" : [{ "bool" : { "must" : [ { "term" : { "lastname.keyword" : { "value" : "Lastname2491", "boost" : 1.0 } } }, { "term" : { "firstname.keyword" : { "value" : "ram", "boost" : 1.0 } } }], "adjust_pure_negative" : true, "boost" : 1.0 } }, { "term" : { "drugname.keyword" : { "value" : "alpha", "boost" : 1.0 } } } ], "adjust_pure_negative" : true, "boost" : 1.0 } }`

---

<div class="post-metadata">

**Author:** ![Anto89](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@Anto89](https://discuss.elastic.co/u/Anto89)\
**Post date:** [February 17, 2020, 2:59pm UTC](https://discuss.elastic.co/t/query-performance-issue-with-the-very-first-one/219418/5 "2020-02-17T14:59:14Z")

</div>

Unfortunately I'm not sure it makes a difference ...  
Slow logs activation seems to highlight that the fetch phase is longer :

> [2020-02-17T14:35:35,840][WARN][index.search.slowlog.fetch] [es-node-02] [index][1] took[5.8s], took\_millis[5843], types[type], stats, search\_type[QUERY\_THEN\_FETCH], total\_shards[2], source[...]

---

<div class="post-metadata">

**Author:** ![Anto89](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@Anto89](https://discuss.elastic.co/u/Anto89)\
**Post date:** [February 18, 2020, 8:15am UTC](https://discuss.elastic.co/t/query-performance-issue-with-the-very-first-one/219418/6 "2020-02-18T08:15:47Z")

</div>

Ok, after reading posts about the same kind of issue, it seems that adding

> "stored\_fields": "_none_"  
> "docvalue\_fields": ["\_id"]

in the query does the trick. More information here : [Avoid the fetch phase when retrieving only \_id · Issue #17159 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/17159)

---

<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 17, 2020, 8:15am UTC](https://discuss.elastic.co/t/query-performance-issue-with-the-very-first-one/219418/7 "2020-03-17T08:15:50Z")

</div>

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