我的ES文档模型如下
"hits": [
{
"_source": {
"variant_group": {
"variant_info": [
{
"name": "Toothpaste",
"inventory": 10
}
],
"type_id": 1365
}
},
]
当我尝试以排序方式执行此查询时:
{
"_script": {
"type": "number",
"order": "desc",
"script": {
"lang": "groovy",
"inline": "return doc['variant_group.variant_info'].values.any{ it -> it.inventory > 0 }"
}
}
}
出现以下错误 在类型为[merchant_variant_group]的映射中找不到[variant_group.variant_info]的字段
我尝试如下使用containsKey
:
{
"_script": {
"type": "number",
"order": "desc",
"script": {
"lang": "groovy",
"inline": "return doc.containsKey('variant_group.variant_info') ? 1 : 0"
}
}
}
此脚本块返回0
而不是1
但是,如果我执行此操作:
{
"_script": {
"type": "number",
"order": "desc",
"script": {
"lang": "groovy",
"inline": "return doc.containsKey('variant_group.type_id') ? 1 : 0"
}
}
}
它返回预期的响应1
收集类型是否缺少我的陷阱,或者我的代码有问题吗?
谢谢!
答案 0 :(得分:0)
应该使用“ doc ['variant_group'] ['variant_info']”或“ doc.variant_group.variant_info”代替“ doc ['variant_group.variant_info']”。我也很幸运与“ _source.variant_group.variant_info”。