gpt4 book ai didi

elasticsearch - Elasticsearch在嵌套数组中搜索

转载 作者:行者123 更新时间:2023-12-03 02:05:33 26 4
gpt4 key购买 nike

嗨,我是Elasticsearch新手,我在查询时遇到了麻烦。我有数据

{
"user_id": "1",
"date": "141462121",
"name": "John",
"surname": "Doe"
"activity": [
{
"type": [
"Outdoor",
"Extreme"
],
"name": "Example",
"price": {
"value": 50,
"currency": "USD"
}
}
]
"searchs": ""
}
},
{
"user_id": "2",
"date": "141462121",
"name": "Jane",
"surname": "Doe"
"activity": [
{
"type": [
"Indoor"
],
"name": "Example2",
"price": {
"value": 100,
"currency": "USD"
}
},
{
"type": [
"Outdoor"
],
"name": "Example3",
"price": {
"value": 25,
"currency": "USD"
}
}
]
"searchs": ""
}
}

我想按 Activity 类型搜索这些数据。我尝试了 nested queries
"query": {
"nested": {
"path": "activity",
"query": {
"bool": {
"must": [
{"match": {
"activity.type": "outdoor"
}}
]
}
}
}

和喜欢
"query": {
"nested": {
"path": "activity",
"query": {
"nested": {
"path": "type",
"query": {
"bool": {
"must": [
{"match": {
"type.value": "outdoor"
}}
]
}
}
}
}
}
}

但我无法成功。

如何按 Activity 类型搜索这些数据?

最佳答案

如果您只是在查找 Activity 类型如下的记录,则可以使用简单的匹配查询

{
"query": {
"match": {
"activity.type": "Outdoor"
}
}
}

关于elasticsearch - Elasticsearch在嵌套数组中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27036535/

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