# Term filter length on performance and Prefix filter

**URL:** <https://discuss.elastic.co/t/term-filter-length-on-performance-and-prefix-filter/17249>\
**Category:** Elasticsearch\
**Created:** [April 29, 2014, 4:30am UTC](https://discuss.elastic.co/t/term-filter-length-on-performance-and-prefix-filter/17249 "2014-04-29T04:30:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arthurx](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@arthurx](https://discuss.elastic.co/u/arthurx)\
**Post date:** [April 29, 2014, 4:30am UTC](https://discuss.elastic.co/t/term-filter-length-on-performance-and-prefix-filter/17249/1 "2014-04-29T04:30:45Z")

</div>

How is the Prefix filter compared to Term filter performance-wise?

For example,  
matching "o1382334"  
with prefix filter of "o" only need to check the first letter, whereas  
using term filter need to match "o1382334" eight letters. Assume they match  
equal number of documents, it seems that prefix filter is more  
"lightweight".

Would someone having an understanding of the underlying algorithm of how  
term filter works comment on this?

A related problem is: is it good for performance to use very long string as  
term filter, like a md5 hash instead of a simple integer ID?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/cc2f2637-42fd-49b3-9ef9-2560f87a9cc2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cc2f2637-42fd-49b3-9ef9-2560f87a9cc2%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [April 29, 2014, 10:09am UTC](https://discuss.elastic.co/t/term-filter-length-on-performance-and-prefix-filter/17249/2 "2014-04-29T10:09:51Z")

</div>

Thanks to the inverted index, terms are only looked up once per segment. So  
I don't think the number of characters to compare would have any  
performance impact.

One benefit of the term filter though might be that the terms dictionary  
index can know that it is not contained in the terms dictionary without  
going to disk.

On Tue, Apr 29, 2014 at 6:30 AM, arthurX [fc28222@gmail.com](mailto:fc28222@gmail.com) wrote:

> How is the Prefix filter compared to Term filter performance-wise?
> 
> For example,  
> matching "o1382334"  
> with prefix filter of "o" only need to check the first letter, whereas  
> using term filter need to match "o1382334" eight letters. Assume they  
> match equal number of documents, it seems that prefix filter is more  
> "lightweight".
> 
> Would someone having an understanding of the underlying algorithm of how  
> term filter works comment on this?
> 
> A related problem is: is it good for performance to use very long string  
> as term filter, like a md5 hash instead of a simple integer ID?
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/cc2f2637-42fd-49b3-9ef9-2560f87a9cc2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cc2f2637-42fd-49b3-9ef9-2560f87a9cc2%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/cc2f2637-42fd-49b3-9ef9-2560f87a9cc2%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/cc2f2637-42fd-49b3-9ef9-2560f87a9cc2%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7PVkFfpoTHMRNXq2YgnE%3D%2B32kEbpgp4mOToYAY6%3DQE7A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7PVkFfpoTHMRNXq2YgnE%3D%2B32kEbpgp4mOToYAY6%3DQE7A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:32am UTC](https://discuss.elastic.co/t/term-filter-length-on-performance-and-prefix-filter/17249/3 "2017-07-06T01:32:48Z")

</div>

Closed on July 6, 2017, 1:32am UTC


