# Optimization question

**URL:** <https://discuss.elastic.co/t/optimization-question/110785>\
**Category:** Elasticsearch\
**Created:** [December 8, 2017, 2:16am UTC](https://discuss.elastic.co/t/optimization-question/110785 "2017-12-08T02:16:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rraulinio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rraulinio/32/25191_2.png) [@rraulinio](https://discuss.elastic.co/u/rraulinio)\
**Post date:** [December 8, 2017, 2:16am UTC](https://discuss.elastic.co/t/optimization-question/110785/1 "2017-12-08T02:16:16Z")

</div>

Hello,

I have been trying to optimize an Elasticsearch query for a few days, but I did not manage to get what I wanted. The scenario is the following: there are **cars** (as the main parent, containing some basic details), **user cars** (child of cars, being added by users, so they can be considered variations of their parent car; parent field is id\_car) and **user cars languages** (child of user cars, which contain text information related to a language, like name and description in english + in french + in german etc; parent field is id\_user\_car). Want I am doing is searching by a given word/sentence into user cars languages values and I retrive what I find + parent user car + parent car. You can see how I got it working from the schema below, but the problem is that I really do not like the response time I get. For example, for a number of ~500 total hits, I get ~150ms response time, which is A LOT. Is there any other way, at all, to do what I want and get a much better response time?

Thank you for your time!

```
{
"query": {
"has_child": {
  "type": "user_car",
  "inner_hits": {
      "_source": "false",
    "size": 1,
    "sort": [
      {
        "price": {
          "order": "asc",
          "mode": "min"
        }
      }
    ]
  },
  "filter": {
    "has_child": {
      "type": "user_car_lang",
      "inner_hits": {
        "_source": "false",
        "size": 1
      },
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "id_lang": 1
              }
            },
            {
              "multi_match": {
                "query": "bmw",
                "fields": [
                  "name",
                  "description"
                ],
                "operator": "and"
              }
            }
          ]
        }
      }
    }
  }
  }
  },
  "_source": "false",
  "size": 1000
}
```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 8, 2017, 2:30am UTC](https://discuss.elastic.co/t/optimization-question/110785/2 "2017-12-08T02:30:13Z")

</div>

> [@rraulinio](#):
>
> I get ~150ms response time

Why is that a lot? What are you comparing it to that is fast?

---

<div class="post-metadata">

**Author:** ![rraulinio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rraulinio/32/25191_2.png) [@rraulinio](https://discuss.elastic.co/u/rraulinio)\
**Post date:** [December 8, 2017, 3:25am UTC](https://discuss.elastic.co/t/optimization-question/110785/3 "2017-12-08T03:25:11Z")

</div>

It's a search query, so ~1 second response time for ~3.5k total hits is a lot, honestly, given the fact that over 50k values can be listed in under 10ms for a simple search query (without any inner hits or related stuff)...

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 8, 2017, 3:27am UTC](https://discuss.elastic.co/t/optimization-question/110785/4 "2017-12-08T03:27:06Z")

</div>

Oh right, it's not obvious from your original post as you only mention the 150ms 🙂

---

<div class="post-metadata">

**Author:** ![rraulinio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rraulinio/32/25191_2.png) [@rraulinio](https://discuss.elastic.co/u/rraulinio)\
**Post date:** [December 8, 2017, 3:30am UTC](https://discuss.elastic.co/t/optimization-question/110785/5 "2017-12-08T03:30:38Z")

</div>

Oh, ok, no problem, sorry for that. As a conclusion, I need help to somehow optimize the query to get a much better response time, as I cannot continue the research only by myself, because time is not my friend... ☹ Thanks in advance!

LE: I am using Elastic 5.6 🙂

---

<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:** [January 5, 2018, 3:30am UTC](https://discuss.elastic.co/t/optimization-question/110785/6 "2018-01-05T03:30:44Z")

</div>

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