如何在弹性搜索中确切匹配?
我想找到确切的匹配。如果没有匹配。我不想 null 。
我正在搜索此ID 6A8C283F-1E75-EC11-8943-000D3A15F525
。 它给了我这个输出
- fcf0dd4e-abbc-ec11-983f-00222482588e9 ,
但它们不匹配ec11
我尝试了此搜索查询
result = await client.search({
index: 'products',
"query": {
"match": {
"sysid":sysid
}
}
})
I want to find exact match .if there is no match .I don't want to null.
I am search this id 6a8c283f-1e75-ec11-8943-000d3a15f525
.
it is giving me this output
- fcf0dd4e-abbc-ec11-983f-0022482588e9
But these it is not matched only ec11
matched
I tried this search query
result = await client.search({
index: 'products',
"query": {
"match": {
"sysid":sysid
}
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是因为您的
sysid
字段是类型text
,因此在索引时间进行分析,并将其标记为fcf0dd4e
,abbc ,
EC11
,8943
和000D3A15F525
。同样,当使用匹配查询搜索时,也将搜索术语分析到以下令牌
6a8c283f
,1E75
,ec11
,8943
,000D3A15F525
。如您所见,匹配有效,因为
ec11
匹配。对于确切的匹配,您需要做的是针对
关键字
字段运行查询。也许您很幸运,您的映射已经包含sysid.keyword
子场。如果没有,您需要更改映射并重新指标数据。然后,您将能够运行
术语
查询,并确切匹配:The problem is because your
sysid
field is of typetext
and is thus analyzed at indexing time and tokenized intofcf0dd4e
,abbc
,ec11
,8943
and000d3a15f525
.Also when searching using a match query, the searched term is analyzed as well into the following tokens
6a8c283f
,1e75
,ec11
,8943
,000d3a15f525
.As you saw, the match works because
ec11
matches.For an exact match, what you need to do is to run your query against a
keyword
field instead. Maybe you're lucky and your mapping already contains asysid.keyword
sub-field. If not, you need to change your mapping and reindex your data.Then you'll be able to run your
term
query like this and get your exact match: