简体   繁体   English

Elasticsearch - 通配符 vs 前缀 vs vs 正则表达式 vs query_string 差异和性能

[英]Elasticsearch - Wildcard vs Prefix vs vs Regexp vs query_string differences and performance

I've just started using Elasticsearch for my project and I want to search like the sql keyword 'like%' does.我刚刚开始在我的项目中使用 Elasticsearch,我想像 sql 关键字'like%'那样进行搜索。

  1. Could anyone please explain what are the differences between Wildcard , Prefix , query_string and Regexp ?谁能解释一下WildcardPrefixquery_stringRegexp之间的区别是什么?

  2. Which one can search with the best performance ?哪个搜索性能最好?

  3. Is it the best way to search rapidly between product tags with defining the keyword field and search with one of the three ways which I mentioned?这是通过定义关键字字段在产品标签之间快速搜索并使用我提到的三种方式之一进行搜索的最佳方式吗?

I appreciate whoever answers me.我感谢回答我的人。

Thanks.谢谢。

Which query is better?哪个查询更好?

Let me answer point by point.让我逐条回答。

  1. Could anyone please explain what are the differences between Wildcard, Prefix, query_string and Regexp?谁能解释一下通配符、前缀、查询字符串和正则表达式之间的区别是什么?

They are very similar in what they can do and how they are implemented.它们在可以做什么以及如何实施方面非常相似。 In fact, wildcard , prefix , and regexp are equally bad in performance .事实上, 通配符前缀和正则表达式在性能上同样糟糕 query_string query allows for a more complex queries, for instance using logical operators like OR and AND . query_string查询允许更复杂的查询,例如使用ORAND等逻辑运算符。 query_string supports wildcards , which I believe are the same wildcards as wildcard query does. query_string支持通配符,我相信通配符与wildcard查询相同。

  1. Which one can search with the best performance?哪个搜索性能最好?

Bottomline: they all are bad.底线:他们都很糟糕。

  1. Is it the best way to search rapidly between product tags with defining the keyword field and search with one of the three ways which I mentioned?这是通过定义关键字字段在产品标签之间快速搜索并使用我提到的三种方式之一进行搜索的最佳方式吗?

I believe that if you use a boolean filter query to reduce amount of matched documents then performance should improve, but the performance gain might still be overwhelmed with how inefficient regexp-like queries from above are.我相信,如果您使用布尔过滤器查询来减少匹配文档的数量,那么性能应该会提高,但性能提升可能仍然会被上面的类似正则表达式的查询效率低下所淹没。

How can I implement autocomplete with Elasticsearch?如何使用 Elasticsearch 实现自动完成?

As you mentioned in the comment above, you would like to implement an autocomplete, so the search_as_you_type data type might be exactly what you are looking for.正如您在上面的评论中提到的,您希望实现自动完成功能,因此search_as_you_type数据类型可能正是您正在寻找的。

Another similar feature is suggesters .另一个类似的功能是建议 Both of them will try to use a more efficient term-based matching, and not regexp-based.他们都将尝试使用更有效的基于术语的匹配,而不是基于正则表达式的匹配。

Hope that helps!希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM