Prefix vs Wildcard vs Regexp in terms of performance and usability

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.*"}}}}}}}
1 Like

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 regexpqueries all work the same internally by creating an automaton that describes matching terms and intersecting it with the terms dictionary.

1 Like

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