# Execution plan for es search?

**URL:** https://discuss.elastic.co/t/execution-plan-for-es-search/65928
**Category:** Elasticsearch
**Created:** [November 14, 2016, 4:04am UTC](https://discuss.elastic.co/t/execution-plan-for-es-search/65928 "2016-11-14T04:04:45Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![famoss](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@famoss](https://discuss.elastic.co/u/famoss)
#### Post date: [November 14, 2016, 4:04am UTC](https://discuss.elastic.co/t/execution-plan-for-es-search/65928/1 "2016-11-14T04:04:46Z")

</div>

If i have a query:

```
"query": {
    "bool": {
        "filter": [
            {
                "term": {
                    "field1": "f1"
                }
            },
            {
                "range": {
                    "field3": {
                        "gt": "1"
                    }
                }
            }
        ]
    }
}

```

The query has two query item,es will create two thread(each thread just execute one query item),and merge result in the end?

Or,es will execute two query item one by one,for example `term "field1":"f1"` just get 100 documents,and then `range field3 gt 1` just filter in the 100 documents instead of all documents?

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [November 14, 2016, 7:15am UTC](https://discuss.elastic.co/t/execution-plan-for-es-search/65928/2 "2016-11-14T07:15:06Z")

</div>

Hi @famoss,

each query is processed by a single thread (per shard). See [the Definitive Guide](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/_query_phase.html) on an in-depth explanation of what's going on under the cover.

Daniel

---

<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: [November 14, 2016, 7:41am UTC](https://discuss.elastic.co/t/execution-plan-for-es-search/65928/3 "2016-11-14T07:41:51Z")

</div>

Also please do not PM people to get answers to your threads.

If you need answers quickly then there are commercial subscriptions to assist you.

---

<div class="post-metadata">

### Author: ![famoss](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@famoss](https://discuss.elastic.co/u/famoss)
#### Post date: [November 14, 2016, 8:05am UTC](https://discuss.elastic.co/t/execution-plan-for-es-search/65928/4 "2016-11-14T08:05:31Z")

</div>

Thank you.Because there is just one thread to execute one query,so i should be care of the filter order?

For example, just as the question,if condition 1 just get 100 documents,and condition 2 can get 1000000 documents,i should place condition 1 before condition 2?

---

<div class="post-metadata">

### Author: ![famoss](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@famoss](https://discuss.elastic.co/u/famoss)
#### Post date: [November 14, 2016, 8:05am UTC](https://discuss.elastic.co/t/execution-plan-for-es-search/65928/5 "2016-11-14T08:05:54Z")

</div>

I'm very sorry

---

<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: [November 14, 2016, 8:39am UTC](https://discuss.elastic.co/t/execution-plan-for-es-search/65928/6 "2016-11-14T08:39:41Z")

</div>

In recent versions of elasticsearch we take care of this internally and we run fastest filters first.  
In old versions, yes, order was super important.

---

<div class="post-metadata">

### Author: ![famoss](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@famoss](https://discuss.elastic.co/u/famoss)
#### Post date: [December 8, 2016, 6:45am UTC](https://discuss.elastic.co/t/execution-plan-for-es-search/65928/7 "2016-12-08T06:45:26Z")

</div>

> In old versions, yes, order was super important

From which version? from `v2+`?

---

<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: [December 8, 2016, 7:02am UTC](https://discuss.elastic.co/t/execution-plan-for-es-search/65928/8 "2016-12-08T07:02:29Z")

</div>

IIRC yes.

---

<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, 2017, 7:02am UTC](https://discuss.elastic.co/t/execution-plan-for-es-search/65928/9 "2017-01-05T07:02:31Z")

</div>

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