elasticsearch查询:获取所有前缀的结果与打字型,自动完整功能匹配的查询
查询 |
---|
我的名字是什么 |
Google是 |
什么是stackoverflow |
如何搜索 |
,所以我想拥有一个具有上述文档的elasticsearch索引。我想获取与查询相匹配的所有前缀的结果。例如,当查询“什么”时,我需要{“我的名字”,“什么是Google”,“ stackoverflow”}作为结果,确切的前缀匹配。
如何创建索引?如果可能的话,示例查询。
提前致谢。
query |
---|
what is my name |
what is google |
what is stackoverflow |
how to search |
So, I would like to have an Elasticsearch Index which has documents as above. I would like to fetch all the results which prefix matches the query. For example, when queried for "what is", I need {"what is my name", "what is google", "what is stackoverflow"} as results, exact prefix match.
How do I go about creating an index? and Example queries, if possible.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有多种方法 ,但最简单的是使用查询,如果您只将数据直接索引到eLasticsearch而不定义映射,则它将自动为您创建两个字段,并且在
.keyword
字段上,您可以使用前缀查询,如下所示。索引示例文档
搜索查询
post/_search
您的预期搜索结果
There are multiple ways to achieve what you want, but simplest is to use the prefix query, if you just index your data directly to Elasticsearch without defining mapping, it will automatically create two fields for you, and on
.keyword
field you can use the prefix query as shown below.Index sample documents
Search query
POST /_search
Your expected search results