elasticsearch - script_fields 总是返回数组。如何返回对象或简单数据类型?
问题描述
我注意到在使用script_fields
它时总是返回应该返回的值的数组。我想知道为什么会发生这种情况,是否可以只返回非数组数据类型,如对象或布尔值?
举例说明(取自网络)
GET sat/_search
{
"script_fields": {
"some_scores": {
"script": {
"lang": "painless",
"inline": "def scores = 0; scores = doc['AvgScrRead'].value + doc['AvgScrWrit'].value; return scores;" <--- we are returning a number here!
}
}
}
}
结果:
{
"_index": "sat",
"_type": "scores",
"_id": "AV3CYR8JFgEfgdUCQSON",
"_score": 1,
"_source": {
"cds": 1611760130062,
"rtype": "S",
"sname": "American High",
"dname": "Fremont Unified",
"cname": "Alameda",
"enroll12": 444,
"NumTstTakr": 298,
"AvgScrRead": 576,
"AvgScrMath": 610,
"AvgScrWrit": 576,
"NumGE1500": 229,
"PctGE1500": 76.85,
"year": 1516
},
"fields": {
"some_scores": [ <----- here it's an array
1152
]
}
}
解决方案
推荐阅读
- unity3d - 防止对撞机在地形中发生故障
- javascript - 计算距离未来日期的时间 - 在变量中正确格式化日期的问题
- php - 获取数组的索引
- sql - 如何在 postgresql 中为不同的表使用嵌套函数?
- amazon-web-services - AWS SNS,向 slack 发送“连续”通知
- firebase - Google Cloud 函数的权限问题
- javascript - 如何将文件从本地主机发送到网站
- class - 对“位置”的未定义引用
::treeHeight' 在类模板构造函数中 - spring-boot - Spring Boot 2 + Spring Security + 登录表单 + Session Redis 不工作
- vue.js - 从存储在 vuex 中的 axios 获取未定义的 response.data