gpt4 book ai didi

Elasticsearch:查询嵌套数组

转载 作者:行者123 更新时间:2023-11-29 02:55:39 24 4
gpt4 key购买 nike

我看到过类似的问题,但当然,没有一个是我想要做的。

当我运行下面的查询时,我得到了这个错误:

"reason": "[nested] failed to find nested object under path [contentGroup]"

我认为问题是 contentGroup.name 不存在,因为 contentGroup 是数组而不是对象。它需要是这样的:内容组[0].名称和内容组[1].名称但我不知道该怎么做。

另一件事可能是错误的,我有两个项目相互嵌套,我不知道这是否正确。

任何帮助都会很棒!

我的映射:

{
"mappings": {
"articles": {
"properties": {
"contentGroups": {
"type": "nested",
"properties": {
"contentGroup": {
"type": "nested",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
}
}
}

当我在文章中输入时会创建什么(注意正在创建的数组):

"contentGroups": {
"contentGroup": [
{
"name": "Breaking",
"id": "104"
},
{
"name": "News",
"id": "22"
}
]

我的查询:

{
"query": {
"bool": {
"must": [
{ "match": { "headline": "whatever" }},
{
"nested": {
"path": "contentGroup",
"query": {
"bool": {
"must": [
{ "match": { "contentGroup.name": "Breaking" }}
]
}
}
}
}
]
}
}

最佳答案

你应该使用更简单的映射:

{
"mappings": {
"articles": {
"properties": {
"contentGroups": {
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
}
}

elasticsearch中的每个字段已经支持多值,无需指定。

关于Elasticsearch:查询嵌套数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36480550/

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