gpt4 book ai didi

搜索查询以在禁用 _source 的情况下在 elasticsearch 中检索嵌套文档

转载 作者:行者123 更新时间:2023-11-29 02:46:07 25 4
gpt4 key购买 nike

我有以下映射

{
"cloth": {
"dynamic" : false,
"_source" : {"enabled" : false },
"properties": {
"name": {
"type": "string",
"index": "analyzed"
},
"variation": {
"type": "nested",
"properties": {
"size": {
"type": "string",
"index": "not_analyzed"
},
"color": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}

我无法找到使用字段查询检索嵌套对象字段的方法。

{
"fields" : ["name" , "variation.size", "variation.color"],
"query" : {
"nested" : {
"path" : "variation",
"query" : {
"bool" : {
"must" : [
{ "term" : { "variation.size" : "XXL" } },
{ "term" : { "variation.color" : "red" } }
]
}
}
}
}
}

上面的查询返回

"_id" : "1",
"_score" : 1.987628,
"fields" : {
"variation.size" : [ "XXL", "XL" ],
"variation.color" : [ "red", "black" ],
"name" : [ "Test shirt" ]
}

当我尝试过

"fields" : ["name" , "variation"]

我得到了错误

status: 400

reason: "ElasticsearchIllegalArgumentException[field [variation] isn't a leaf field]"

这是预期的。

我怎样才能按原样获得变体对象?

预期结果。我需要检索整个变量对象,以便我可以保留大小和颜色的关联。就像“红色”和“XXL”一样。

"variation" : { "XXL" , "red"}

更新:此索引类型的来源已禁用。

最佳答案

如果您使用 Source Filtering它将作为一个整体返回嵌套对象,您的查询将是:

{
"_source": [
"name",
"variation"
],
"query": {
"nested": {
"path": "variation",
"query": {
"bool": {
"must": [
{
"term": {
"variation.size": "XXL"
}
},
{
"term": {
"variation.color": "red"
}
}
]
}
}
}
}
}

关于搜索查询以在禁用 _source 的情况下在 elasticsearch 中检索嵌套文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26182063/

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