elasticsearch常用查询

1.班级学生求每个学生的平均分 学生分数为string类型,需要在聚合时转换为float

通过script转换类型

{"fields":["data"],"query":{"bool":{"must":[{"range":{"class_id":{"from":1}}}]}},
"aggs":{"stu_id":{"terms":{"field":"stu_id","size":600,"collect_mode":"breadth_first","execution_hint":"map"},
"aggs":{"score":
{"avg":{
"script":"Float.parseFloat(doc['score'].value)"}}}}}}

2.通过查询删除数据:

示例:通过modify_time删除

curl -XDELETE 'http://localhost:9200/index_name/_query?pretty' -d '{"query": {"bool": {"must":[{"range":{"modify_time":{"to":1562342400}}}]}}}'

原文地址:https://www.cnblogs.com/supermanwx/p/11512082.html