假设Elastic search中一个index存储了系统中的文章及其赞赏记录,赞赏记录中包括赞赏者姓名和赞赏金额,这种情况下需要在elastic search中使用nested类型的内嵌对象.因为如果使用数组或者...,需要使用nested query
GET articles/_search
{
"query": {
"nested": {
"path": "payment",...,需要注意的是,查询语句中要指定查询字段的全名,所以赞赏者姓名要用"payment.name"
如果在多个index上进行nested查询,没有nested字段的index会报错,这时可以将ignore_unmapped...设置为true
4 如果想查看赞赏的平均金额,需要用nested aggregation
GET articles/_search
{
"size": 0,
"aggs": {
"nested..."field": "payment.amount"
}
}
}
}
}
}
同样注意要用path指定字段名称,返回的数据中