# First query is slow even if I use "loading:eager"

**URL:** <https://discuss.elastic.co/t/first-query-is-slow-even-if-i-use-loading-eager/63374>\
**Category:** Elasticsearch\
**Created:** [October 19, 2016, 10:45am UTC](https://discuss.elastic.co/t/first-query-is-slow-even-if-i-use-loading-eager/63374 "2016-10-19T10:45:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![avion](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@avion](https://discuss.elastic.co/u/avion)\
**Post date:** [October 19, 2016, 10:45am UTC](https://discuss.elastic.co/t/first-query-is-slow-even-if-i-use-loading-eager/63374/1 "2016-10-19T10:45:09Z")

</div>

I'm using this kind of mapping (well, it's a shortener version in order to make the question easier) on a children-parent relationship where `item` is the `parent` and `user_items` is the `children`.

```
    curl -XPUT 'localhost:9200/myindex?pretty=true' -d '{
      "mappings": {
        "items": {
           "dynamic": "strict",
           "properties" : {
                "title" : { "type": "string" },
                "body" : { "type": "string" },
    }},
        "user_items": {
          "dynamic": "strict",
          "_parent": {"type": "items" },
          "properties" : {
                "user_id" : { "type": "integer" },
                "source_id" : { "type": "integer" },
    }}}}'

```

And the type of query I usually make:

```
    curl -XGET 'localhost:9200/myindex/items/_search?pretty=true' -d '{
        "query": {
          "bool": {
             "must": [
                {
                   "query_string": {
                      "fields": ["title", "body"],
                      "query": "mercado"
                   }
                },
                {
                   "has_child": {
                      "type": "user_items",
                      "query": {
                         "term": {
                            "user_id": 655
        }}}}]}}}'

```

On this query it has to search on the fields `title` and `body` the string `mercado` on a given `user_id`, in this case `655`.

The first of these query is veeeeeeeeeeeeeeeery slow, it can take up to 15 seconds. The following ones are quite fast (\<0.5 sec)

I read that the reason of being so slow the first query is that it gets cacheed and then the rest queries are fast because it works with the cached content.

I read I can use `"loading" : "eager"` to boost the first query. So I created a new mapping on a new index with the name `myindex_new`

```
    {
      "mappings": {
        "items": {
           "dynamic": "strict",
           "properties" : {
                "title" : { "type": "string" ,
                            "fielddata": {
                                "loading" : "eager"}},
                "body" : { "type": "string",
                            "fielddata": {
                                "loading" : "eager"}},
    }},
        "user_items": {
          "dynamic": "strict",
          "_parent": {"type": "items" },
          "properties" : {
                "user_id" : { "type": "integer" },
                "source_id" : { "type": "integer" },
    }}}}'

```

... and reindexed everything as follows:

```
curl -XPOST 'localhost:9200/_reindex' -d '{
    "source" : {
        "index" : "myindex"
    },
    "dest" : {
        "index" : "myindex_new"
    }
}'

```

The thing is that I'm not getting any better results. The first query is still slow if I query the new index with the `eager` on it. I also tried by adding the `eager` on the child fields but its still slow.

Do I've to make anything different? I'm doing something wrong on the re-index or something?

Thanks in advance!

---

<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:** [July 5, 2017, 10:11pm UTC](https://discuss.elastic.co/t/first-query-is-slow-even-if-i-use-loading-eager/63374/2 "2017-07-05T22:11:18Z")

</div>


