如何解决弹性搜索:正则表达式,用于匹配自动完成提示器中字符串列表中的最长字符串
我对弹性搜索非常陌生,并尝试使用正则表达式查询实现自动完成提示。收到查询后,我将查询最后5个单词,并以这种格式形成令牌列表
query - i am trying regex for elasticsearch
tokens - [elasticsearch,for elasticsearch,regex for elasticsearch ...]
我的要求是从索引列表中识别与最长字符串匹配的索引句子 我很难为它编写正则表达式。有人可以帮忙吗?
我的映射:
"mappings": {
"properties": {
"keywords": {
"type": "text","fields": {
"keywords_suggest": {
"type": "completion"
}
}
},"sections": {
"type": "text","fields": {
"sections_suggest": {
"type": "completion"
}
}
},"title": {
"type": "text","fields": {
"title_suggest": {
"type": "completion"
}
}
}
这就是我发出搜索请求的方式
body = {
"from": 0,"size": size,"query": {
"multi_match": {
"query": query,"fields": ["title^3","searchResultPreview^1","body^5"],#ignore these fields as i only pasted mapping used for completion type
"fuzziness": "AUTO"
}
},"suggest": {
"title-suggest": {
"regex": regex,"completion": {
"field": "title.title_suggest","skip_duplicates": True,}
},"keyword-suggest": {
"regex": regex,"completion": {
"field": "keywords.keywords_suggest","section-suggest": {
"regex": regex,"completion": {
"field": "sections.sections_suggest",}
}
}
}
search_result = self.es.search(index=index_name,body=body)
Indexed sentence1 - The Real purpose of elasticsearch is unknown
Indexed sentence2 - real function is not defined
query - i want to know the real
list of words - [ real,the real,know the real,to know the real]
我尝试遵循正则表达式-
(to know the real|know the real|the real|real)
必需的输出-已索引的句子1需要匹配,因为它是该句子开头的列表中最长的单词,但显示的内容仅匹配以实数开头的句子
有人可以告诉我,我要去哪里了。
编辑:我认为区分大小写不是问题,因为真实单词的匹配不区分大小写
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。