# Reverse keyword vs new Wildcard data type

**URL:** <https://discuss.elastic.co/t/reverse-keyword-vs-new-wildcard-data-type/245751>\
**Category:** Elasticsearch\
**Created:** [August 20, 2020, 10:46am UTC](https://discuss.elastic.co/t/reverse-keyword-vs-new-wildcard-data-type/245751 "2020-08-20T10:46:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheWorkingDeveloper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theworkingdeveloper/32/90834_2.png) [@TheWorkingDeveloper](https://discuss.elastic.co/u/TheWorkingDeveloper)\
**Post date:** [August 20, 2020, 10:46am UTC](https://discuss.elastic.co/t/reverse-keyword-vs-new-wildcard-data-type/245751/1 "2020-08-20T10:46:18Z")

</div>

In email wildcard searching:

```auto
user_email*
*@domain.com

```

Would reverse keyword be faster in searching than wildcard given a single wildcard?

`moc.niamod@*` on reverse keyword  
vs  
`*@domain.com` on wildcard  
For example.

Solved:  
For this specific use case: Reverse keyword is fastest

---

<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:** [August 20, 2020, 11:04am UTC](https://discuss.elastic.co/t/reverse-keyword-vs-new-wildcard-data-type/245751/2 "2020-08-20T11:04:38Z")

</div>

It's all about index and query alignment.  
If you build your own index and ensure related queries are similarly treated then you can use an index with reversed tokens efficiently for the `*@domain.com` search and a different index with non-reversed tokens for making a `bill.gates@*` search efficient. If you use the wrong query on the wrong index you end up scanning all unique values in the index rather than being able to quickly seek to the relevant parts. There's no safety rails to prevent you picking the wrong field.  
That said, if you bothered to create the appropriate index and the searcher picked the right field then it should be quick and there's no need to verify each of the docs that have that term.

With wildcard field it's a more general-purpose index. One index does leading and trailing wildcards (and arbitrarily complex regex) searches. It has ngram index entries for every character position in the string to make it fast. The downside is that matching purely on this ngram index is not sufficient evidence of a match - for each candidate matched doc the engine also needs to verify that the search expression is indeed in that doc by some follow-up testing (this happens automatically behind the scenes). If you have many docs containing the search term we will have to test each of them. Small numbers of matches will be much quicker.

So it depends. It's unlikely to beat a carefully custom-designed combo of index and query but there's more versatility and less need for multiple data structures.

---

<div class="post-metadata">

**Author:** ![TheWorkingDeveloper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theworkingdeveloper/32/90834_2.png) [@TheWorkingDeveloper](https://discuss.elastic.co/u/TheWorkingDeveloper)\
**Post date:** [August 20, 2020, 11:21am UTC](https://discuss.elastic.co/t/reverse-keyword-vs-new-wildcard-data-type/245751/3 "2020-08-20T11:21:45Z")

</div>

> [@Mark\_Harwood](#):
>
> If you build your own index and ensure related queries are similarly treated then you can use an index with reversed tokens efficiently for the `*@domain.com` search and a different index with non-reversed tokens for making the

So generalizing the answer. A reverse keyword search would be faster given more matching results for the specific instance of searching emails part of a domain?  
This is assuming the correct field is searched by the program/website/system/user with the appropriate query.

---

<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:** [August 20, 2020, 11:28am UTC](https://discuss.elastic.co/t/reverse-keyword-vs-new-wildcard-data-type/245751/4 "2020-08-20T11:28:09Z")

</div>

> [@TheWorkingDeveloper](#):
>
> A reverse keyword search would be faster given more matching results for the specific instance of searching emails part of a domain?

Yes. It would not be faster for that specific use case with that specific indexing.  
The plus is that the wildcard field would support fast `bill.gates@*`, `*@domain.com`, `bill*@domain.*`, `[b|w]ill.*domain\.(org|com)` etc queries too without needing additional indexed fields.

---

<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 17, 2020, 11:28am UTC](https://discuss.elastic.co/t/reverse-keyword-vs-new-wildcard-data-type/245751/5 "2020-09-17T11:28:19Z")

</div>

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