如何获取与Elasticsearch中匹配的单词令牌
- 我需要匹配的单词值列表。如果我的搜索字符串为
abc
,它是我的名称,我的预期列出的是值列表[abcdef
,abcdefgh
,.. ...]
myd在
[
{'id':1, 'name': 'christiano ronaldo', 'description': 'portugal'},
{'id':2, 'name': 'lionel messi', 'description': 'argentina'},
{'id':3, 'name': 'Lionel Jr', 'description': 'brazil'}
]
DSL查询下方的MyD下方是
{
"query": {
"match_phrase_prefix": {
"name": {
"query": "lio",
"slop": 3,
}
}
}
}
我的输出下方
{'took': 2,
'timed_out': False,
'_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0},
'hits': {'total': {'value': 2, 'relation': 'eq'},
'max_score': 0.4700036,
'hits': [{'_index': 'players',
'_type': '_doc',
'_id': '2',
'_score': 0.4700036,
'_source': {'id': 2, 'name': 'lionel messi', 'description': 'argentina'}},
{'_index': 'players',
'_type': '_doc',
'_id': '3',
'_score': 0.4700036,
'_source': {'id': 3, 'name': 'Lionel Jr', 'description': 'brazil'}}]}}
- ,有任何方法可以提取
像我预期的那样匹配的令牌单词,只是lionel
lio 匹配Lionel
和Lionel
的名称
- I need list of values of words which matches. if my search string is
abc
which is theere in my name of document my expected out is just list of values [abcdef
,abcdefgh
, .....]
myd is below
[
{'id':1, 'name': 'christiano ronaldo', 'description': 'portugal'},
{'id':2, 'name': 'lionel messi', 'description': 'argentina'},
{'id':3, 'name': 'Lionel Jr', 'description': 'brazil'}
]
DSL query is below
{
"query": {
"match_phrase_prefix": {
"name": {
"query": "lio",
"slop": 3,
}
}
}
}
My output is below
{'took': 2,
'timed_out': False,
'_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0},
'hits': {'total': {'value': 2, 'relation': 'eq'},
'max_score': 0.4700036,
'hits': [{'_index': 'players',
'_type': '_doc',
'_id': '2',
'_score': 0.4700036,
'_source': {'id': 2, 'name': 'lionel messi', 'description': 'argentina'}},
{'_index': 'players',
'_type': '_doc',
'_id': '3',
'_score': 0.4700036,
'_source': {'id': 3, 'name': 'Lionel Jr', 'description': 'brazil'}}]}}
- is there any way to extract the token word which matches
Like my expected out is only is just lionel
only as lio
matches the name which is lionel
and Lionel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,没有直接的方法可以在搜索结果中获得文本的匹配令牌。
但是,一种方法是使用 ighlighting 文本中的匹配术语。
您可以解析搜索结果响应,并在应用程序方面检索突出显示的术语。
As far as I'm aware, there is no direct way to get only the text's matched tokens in the search result.
However, one method is to use highlighting to get the matching terms in the text.
You can parse the search result response and retrieve the highlighted terms later on the application side.