gpt4 book ai didi

elasticsearch - elasticsearch在嵌套类型内搜索数组字段

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

我正在尝试使用嵌套过滤器过滤结果,但是我得到的结果不正确

这是我的 map 信息

{
"stock" : {
"mappings" : {
"clip" : {
"properties" : {
"description" : {
"type" : "string"
},
"keywords" : {
"type" : "nested",
"properties" : {
"category" : {
"type" : "string"
},
"tags" : {
"type" : "string",
"index_name" : "tag"
}
}
},
"tags" : {
"type" : "string",
"index_name" : "tag"
},
"title" : {
"type" : "string"
}
}
}
}
}
}

剪辑文档数据
{
"_index" : "stock",
"_type" : "clip",
"_id" : "AUnsTOBBpafrKleQN284",
"_score" : 1.0,
"_source":{
"title": "journey to forest",
"description": "this clip contain information about the animals",
"tags": ["birls", "wild", "animals", "roar", "forest"],
"keywords": [
{
"tags": ["spring","summer","autumn"],
"category": "Weather"
},
{
"tags": ["Cloudy","Stormy"],
"category": "Season"
},
{
"tags": ["Exterior","Interior"],
"category": "Setting"
}
]
}

我正在尝试过滤嵌套字段“关键字”内的标签
这是我的查询
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "keywords",
"filter": {
"bool": {
"must": [
{
"terms": { "tags": ["autumn", "summer"] }
}
]
}
}
}

}
}
}
}

我没有结果为什么?
我的查询或架构出了什么问题,请帮忙

最佳答案

上面的查询在语法上是错误的。您需要提供术语查询中根关键字标签的完整路径,即关键字。tags

{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "keywords",
"filter": {
"bool": {
"must": [
{
"terms": { "keywords.tags": ["autumn", "summer"] }
}
]
}
}
}

}
}
}
}

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

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