# Difference between queries

**URL:** <https://discuss.elastic.co/t/difference-between-queries/118106>\
**Category:** Elasticsearch\
**Created:** [February 1, 2018, 9:13pm UTC](https://discuss.elastic.co/t/difference-between-queries/118106 "2018-02-01T21:13:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mario12](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mario12/32/29324_2.png) [@mario12](https://discuss.elastic.co/u/mario12)\
**Post date:** [February 1, 2018, 9:13pm UTC](https://discuss.elastic.co/t/difference-between-queries/118106/1 "2018-02-01T21:13:07Z")

</div>

1. "query": {  
"range": { createTime: { "gte": "1483142400000" } }  
}

2. "filtered": {  
"query": {  
"match\_all": {}  
},  
"filter":  
{ "range": { "createTime": { "gte": "1483142400000" }}}  
}  
}

3. Can you please let me know what is the difference between two queries?

4. If the output of both queries are same can you please let me know which query executes faster?

5. Is there a better way to write this query?

---

<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:** [February 1, 2018, 9:25pm UTC](https://discuss.elastic.co/t/difference-between-queries/118106/2 "2018-02-01T21:25:33Z")

</div>

As you seem using an old version, the second might be faster.

In 6.x, you will have to use a bool query with a filter clause.

---

<div class="post-metadata">

**Author:** ![mario12](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mario12/32/29324_2.png) [@mario12](https://discuss.elastic.co/u/mario12)\
**Post date:** [February 1, 2018, 9:37pm UTC](https://discuss.elastic.co/t/difference-between-queries/118106/3 "2018-02-01T21:37:12Z")

</div>

Thanks @dadoonet. We are using es 2.4. Why is the second query better than the first?

---

<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:** [February 1, 2018, 10:03pm UTC](https://discuss.elastic.co/t/difference-between-queries/118106/4 "2018-02-01T22:03:06Z")

</div>

It does not participate to scoring and can be cached then.

---

<div class="post-metadata">

**Author:** ![mario12](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mario12/32/29324_2.png) [@mario12](https://discuss.elastic.co/u/mario12)\
**Post date:** [February 2, 2018, 12:15am UTC](https://discuss.elastic.co/t/difference-between-queries/118106/5 "2018-02-02T00:15:15Z")

</div>

We are planning to use this query for re-indexing purpose (used in the source indices to filter data). So, caching will not help. Do you still think the second query is better?

---

<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:** [February 2, 2018, 7:35am UTC](https://discuss.elastic.co/t/difference-between-queries/118106/6 "2018-02-02T07:35:45Z")

</div>

Yes. I still think it.

---

<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 2, 2018, 7:35am UTC](https://discuss.elastic.co/t/difference-between-queries/118106/7 "2018-03-02T07:35:50Z")

</div>

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