如何使用嵌套字段在查询脚本中使用键和数据参数进行排序?
数据:
{ ID: { “代码”:“ 01cktwwyfnyt9d2nqj9ycwxcme”, “名称”:“ ABC” }
code
和name
嵌套在id
下。
{
"sort": [{
"_script": {
"type": "number",
"script": {
"lang": "painless",
"inline": "if(params.scores.containsKey(doc['id.code'].value)) { return params.scores[doc['id.code']];} return 1000;",
"params": {
"scores": {
"01cktwwyfnyt9d2sasasawxcme": 0,
"01cktwwyfnyt9d2nqj9ycwxcme": 1,
"01chyvzv678r1h0y0rx4e4bv8t": 2
}
}
},
"order": "asc"
}
}],
"_source": {
"includes": ["id.code"]
}
}