# Why term query, keyword is faster than number

**URL:** <https://discuss.elastic.co/t/why-term-query-keyword-is-faster-than-number/264812>\
**Category:** Elasticsearch\
**Created:** [February 19, 2021, 8:12am UTC](https://discuss.elastic.co/t/why-term-query-keyword-is-faster-than-number/264812 "2021-02-19T08:12:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![asasas234](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asasas234/32/113152_2.png) [@asasas234](https://discuss.elastic.co/u/asasas234)\
**Post date:** [February 19, 2021, 8:12am UTC](https://discuss.elastic.co/t/why-term-query-keyword-is-faster-than-number/264812/1 "2021-02-19T08:12:25Z")

</div>

I saw in [Tune for search speed | Elasticsearch Reference [7.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-search-speed.html#map-ids-as-keyword), in term query, keyword query The speed is faster than the digital type, but I am not sure what the reason is. Is there any blog or document that explains this? What I have always understood before is that numeric queries are always faster than strings

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 19, 2021, 8:26am UTC](https://discuss.elastic.co/t/why-term-query-keyword-is-faster-than-number/264812/2 "2021-02-19T08:26:00Z")

</div>

> [@asasas234](#):
>
> t I'm not sure why, is there a blog or document that explains this?

An exact query on a numeric value is turned into a range query eg from 274637 to 274637.  
The underlying data structure is optimised for retrieving blocks of values covered by a ranges rather than individual unique values.

You can test the effects yourself with this [test rig](https://gist.github.com/markharwood/3b5519338045a12115a41fc5b72355fa)  
I found the speed difference wasn’t noticeable as part of all the other things a search does until the query had many terms. Then the overhead becomes apparent and with 100 terms I was seeing four times slower responses.

---

<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 19, 2021, 8:26am UTC](https://discuss.elastic.co/t/why-term-query-keyword-is-faster-than-number/264812/3 "2021-03-19T08:26:49Z")

</div>

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