Elasticsearch / OpenSearch术语搜索逻辑或
我一直在挠头一段时间,查看OpenSearch文档和Stackoverflow问题。我该怎么做类似的事情:
选择文档在[1234,5678]中的studentId或[2468,1357]中的applicationID
中。
只要StudentId
与提供的值之一完全匹配,或者applicationId
与所提供的值匹配之一,则该文档应包含在响应中。
当我想为单个字段搜索多个值并获得以下工作的确切匹配时:
{
"must":[
{
"terms": {
"studentId":["1234", "5678"]
}
}
]
}
这将在[1234,5678] 中找到studentId上的完全匹配。
如果我尝试添加条件,以便在[2468,1357] 中查找(逻辑或)applicationID
,那么以下内容将无效:
{
"must":[
{
"terms": {
"studentId":["1234", "5678"]
}
},
{
"terms": {
"applicationId":["2468", "1357"]
}
}
]
}
因为这将进行逻辑和在两个查询中。我想要逻辑或。
我不能使用应该
,因为这会返回不相关的结果。以下内容对我不起作用:
{
"should":[
{
"terms": {
"studentId":["1234", "5678"]
}
},
{
"terms": {
"applicationId":["2468", "1357"]
}
}
]
}
这似乎返回所有结果,并以相关性排名。我发现,尽管这是术语
搜索,但返回的结果实际上不匹配。
I have been scratching my head for a while looking at OpenSearch documentation and stackoverflow questions. How can I do something like this:
Select documents WHERE studentId in [1234, 5678] OR applicationId in [2468, 1357]
.
As long as studentId
exactly matches one of the supplied values, or applicationId
exactly matches one of the supplied values, then that document should be included in the response.
When I want to search for multiple values for a single field and get an exact match the following works:
{
"must":[
{
"terms": {
"studentId":["1234", "5678"]
}
}
]
}
This will find me exact matches on studentId in [1234, 5678]
.
If I try to add the condition to also look for (logical or) applicationId in [2468, 1357]
then the following will not work:
{
"must":[
{
"terms": {
"studentId":["1234", "5678"]
}
},
{
"terms": {
"applicationId":["2468", "1357"]
}
}
]
}
because this will do a logical and on the two queries. I want logical or.
I cannot use should
because this returns irrelevant results. The following does not work for me:
{
"should":[
{
"terms": {
"studentId":["1234", "5678"]
}
},
{
"terms": {
"applicationId":["2468", "1357"]
}
}
]
}
This seems to return all results, ranked by relevance. I find that the returned results do not actually match, despite the fact that this is a terms
search.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试以下查询。
Can you try with following query..