elasticsearch - Searching for a term as both a single string and multi worded string
问题描述
I'm setting up my elastic instance in a schema-less manner (no up front mappings) and the application requires users be able to search against a field that contains a word that may or may not be tokenized into multiple strings. For example, the field may contain the word "ONETWO". The spec requires that a user should be able to search "ONETWO", "ONE", and "TWO" and retrieve that same document. There doesn't seem any easy way to accomplish this even with a custom tokenizer (and I don't think there SHOULD be an easy way to do this -- or any way at all). Just want to confirm my thoughts.
解决方案
使用使用n-gram 标记器的自定义分析器很容易满足您的要求,您甚至可以将其传递给小写标记过滤器,这样在您的情况下,即使您的文本也是如此,ONETWO
但如果用户搜索one
, One
,ONE
他应该得到一个结果。尽管为此您需要应用不同的分析器搜索时间,但请阅读有关它的更多信息 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html。
有关更多信息,请参阅https://devticks.com/how-to-improve-your-full-text-search-in-elasticsearch-with-ngram-tokenizer-e346f29f8ddb,如果您需要任何信息,请告诉我。
推荐阅读
- ruby-on-rails - 无法运行将用户戳添加到现有表 Rails 的迁移
- c++ - 队列没有保存更新的数据
- python - 将文件变量从 python 脚本传递到 bash 脚本
- flutter - Flutter:向 Text 小部件添加一个简单的包装器
- r - RDCOMClient 删除自动过滤器
- python - Opencv Python,将点云投影到平面上,然后将平面转换为图像
- powershell - Powershell根据上次修改日期重命名文件
- python - 创建一个词汇游戏
- google-bigquery - BigQuery 限制表删除
- c++ - 基于 C++ 范围的循环——它们是如何工作的?