1、统计loginName去重后的数量
GET /login_user_info/_search
{
"size":0,
"query":{"bool":{"filter":[{"terms":{"systemCd.keyword":["AAAAA"]}},
{"query_string":{"default_field":"userTypeCd.keyword","query":"2"}}],"adjust_pure_negative":true,"boost":1.0}},
"track_total_hits":2147483647,
"aggregations":{"userNum":{"cardinality":{"field":"loginName.keyword"}}}
}
2、将customer的值替换为loginName的值
POST login_user_info/_update_by_query
{
"query":{"bool":{"filter":[{"query_string":{"default_field":"systemCd.keyword","query":"AAAAA"}},
{"query_string":{"default_field":"userTypeCd.keyword","query":"2"}}],"adjust_pure_negative":true,"boost":1.0}},
"script":{"inline": "ctx._source['customer'] = ctx._source['loginName']"},
"track_total_hits":2147483647
}
3、时间范围查询
GET /login_user_info/_search
{
"query":{"bool":{"filter":[{"range":{"createTime":{"from":"2020-09-01T00:00:00.000Z","to":"2020-10-31T23:59:59.000Z",
"include_lower":true,"include_upper":true,"boost":1.0}}}],
"adjust_pure_negative":true,"boost":1.0}},
"track_total_hits":2147483647
}
4、异步多线程删除数据
# wait_for_completion=false : 开启异步 # scroll_size=2000 : 删除文档数 # slices=2 : 线程数量 # conflicts=proceed : 冲突继续执行 POST login_user_info/_delete_by_query?wait_for_completion=false&conflicts=proceed&scroll_size=10000&slices=10 {"query":{"bool":{"filter":[{"range":{"createTime":{"from":"2020-09-01T00:00:00.000Z", "to":"2020-10-31T23:59:59.000Z","include_lower":true,"include_upper":true,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}},"track_total_hits":2147483647}
5、计算user索引下每个systemCd下的文档数量, 请求语法
GET user/_search
{
"size": 0,
"from": 20,
"aggs": {
"group_by_tags": {
"terms": {
"field": "systemCd.keyword"
}
}
},"track_total_hits":2147483647
}