# Prefix vs Wildcard vs Regexp in terms of performance and usability

**URL:** <https://discuss.elastic.co/t/prefix-vs-wildcard-vs-regexp-in-terms-of-performance-and-usability/98460>\
**Category:** Elasticsearch\
**Created:** [August 26, 2017, 6:48pm UTC](https://discuss.elastic.co/t/prefix-vs-wildcard-vs-regexp-in-terms-of-performance-and-usability/98460 "2017-08-26T18:48:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BentCoder](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@BentCoder](https://discuss.elastic.co/u/BentCoder)\
**Post date:** [August 26, 2017, 6:48pm UTC](https://discuss.elastic.co/t/prefix-vs-wildcard-vs-regexp-in-terms-of-performance-and-usability/98460/1 "2017-08-26T18:48:18Z")

</div>

Hi,

I have queries below which work like `SELECT * FROM table WHERE raw.name LIKE 'Product1*'`. I just want to find out which one would be the best in terms of performance and usability?

Thanks

```
{"query":{"prefix":{"name.raw":"Product1"}}}

{"query":{"wildcard":{"name.raw":"Product1*"}}}

{"query":{"regexp":{"name.raw":"Product1.*"}}}

{"query":{"bool":{"must":{"prefix":{"name.raw":"Product1"}}}}}

{"query":{"bool":{"must":{"wildcard":{"name.raw":"Product1*"}}}}}

{"query":{"bool":{"must":{"regexp":{"name.raw":"Product1.*"}}}}}

{"query":{"filtered":{"filter":{"bool":{"must":{"regexp":{"name.raw":"Product1.*"}}}}}}}
```

---

<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:** [September 1, 2017, 12:38pm UTC](https://discuss.elastic.co/t/prefix-vs-wildcard-vs-regexp-in-terms-of-performance-and-usability/98460/2 "2017-09-01T12:38:54Z")

</div>

All those queries are equally bad: boolean queries with a single clause are rewritten to that clause so wrapping in a `bool` or `filtered` query has no effect.

Also `prefix`, `wildcard` and `regexp`queries all work the same internally by creating an automaton that describes matching terms and intersecting it with the terms dictionary.

---

<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:** [September 29, 2017, 12:46pm UTC](https://discuss.elastic.co/t/prefix-vs-wildcard-vs-regexp-in-terms-of-performance-and-usability/98460/3 "2017-09-29T12:46:14Z")

</div>

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