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

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!

1 Like