gpt4 book ai didi

json - 在ElasticSearch中使用字段和提供的ID进行简单搜索

转载 作者:行者123 更新时间:2023-12-02 23:40:30 25 4
gpt4 key购买 nike

我只想在ElasticSearch中搜索与多个字段匹配的用户,并在那里找到文档ID。目前,我有此代码只能匹配多个字段,并且运行良好

{ 
"query" :
{
"multi_match": {
"fields": [
"user",
"email"
],
"query": "John",
"operator": "and",
"type": "phrase_prefix"
}
}
}

但是现在只需要一点帮助,我如何才能确保仅搜索文档ID为[“5”,“4”]的文档?

我试过了
{ 
"query" :
{
"multi_match": {
"fields": [
"user",
"email"
],
"query": "John",
"operator": "and",
"type": "phrase_prefix"
},
"filter" : {
"ids" : {
"values" : ["5","4"]
}
}
}
}

但这是行不通的。这是错的吗?在存储每个文档时,我给自己一个唯一的ID。我没有过滤器的查询结果是这样的
"hits": [
{
"_index": "MyIndex",
"_type": "users",
"_id": "4",
"_score": 0.70710677,
"_source": {
"user": "John Ibraheem",
"email": "johnibrhaeem@yahoo.com"
}
},
{
"_index": "MyIndex",
"_type": "users",
"_id": "9",
"_score": 0.70710677,
"_source": {
"user": "Johnathan",
"email": "johnathan@yahoo.com"
}
},
{
"_index": "MyIndex",
"_type": "users",
"_id": "5",
"_score": 0.30685282,
"_source": {
"user": "Johnsons",
"email": "johnsons@gmail.com"
}
}
]

我只想获取_id为[“5”,“4”]而不是“9”的John *。

最佳答案

试试这个

{
"query":
{
"filtered":
{
"query":
{
"multi_match":
{
"fields": ["user","email"],
"query": "i",
"operator": "and",
"type": "phrase_prefix"
},
"filter" : {
"ids" : {
"values" : ["5","9"]
}
}
}
}
}
}

关于json - 在ElasticSearch中使用字段和提供的ID进行简单搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22027768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com