elasticsearch查询命令行


elasticsearch的查询命令行

1
如何解决es根据某个值去重不准确的问题,将需要去重的值和被根据的值组成唯一值
1
注意: 不要使用_id排序,性能很差
1
2
3
4
5
6
7
8
9
10
将index1中的数据重新索引到index2中,使用index2的数据类型,记得查看_id是否被修改,有时候_id不变,有时候会被修改
POST _reindex?wait_for_completion=false
{
"source": {
"index": "index1"
},
"dest": {
"index": "index2",
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
更新,如果"售后字段不存在",则更新为0
POST prod_alipay_settlement_detail/_update_by_query?wait_for_completion=false
{
"script": {
"source": "ctx._source['售后'] = 0",
"lang": "painless"
},
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "售后"
}
}
]
}
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
查询根据yyyyyyy聚合后, xxxxxxxx去重后数量>1的记录 相当于mysql的having count >1
GET prod_delivery_file/_search
{
"size": 0,
"aggs": {
"refund": {
"aggs": {
"rs": {
"cardinality": {
"field": "xxxxxxxx"
}
},
"count_filter": {
"bucket_selector": {
"buckets_path": {
"count": "rs"
},
"script": "params.count > 1"
}
}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
更新

POST index/_update_by_query?wait_for_completion=false
{
"script": {
"source": "ctx._source.xxxx = 'xxxxx'",
"lang": "painless"
},
"query": {
"match": {
"xxxxxyyyyy": "xxxxxyyyyy"
}
}
}

返回task_id
使用GET _tasks/T9aamlpWS_SNJDEYJIPfew:127191429 查看任务执行情况
使用POST _tasks/T9aamlpWS_SNJDEYJIPfew:127191429/_cancel 结束任务
1
2
查看所有索引
curl -X GET "http://host:port/_cat/indices/?v"
1
2
查看某个索引
curl -X GET "http://host:port/_cat/indices/index*?v"
1
2
查看index下的10条记录
curl -X GET "http://host:port/index/_search"
1
2
查看index的数量
curl -X GET "http://host:port/index/_count"
1
2
查看index的订单123123123123123
curl -X GET "http://host:port/index/_doc/123123123123123?pretty"
1
2
查看index的订单 根据order_no查看123123123123123
curl -X GET "http://host:port/index/_search?q=order_no:123123123123123"
1
2
3
4
5
6
7
8
9
10
查看index的订单 search_key=data
curl -X GET "http://host:port/index/_search" -H "Content-Type: application/json" -d '
{
"query": {
"match": {
"search_key": "data"
}
},
"size": 5
}'
1
2
3
4
5
6
7
8
9
10
11
查看index的订单 search_key1=123123123123123 or search_key2=123123123123123
curl -X GET "http://host:port/index/_search" -H "Content-Type: application/json" -d '
{
"query": {
"multi_match": {
"query":"123123123123123",
"fields": ["search_key1", "search_key2"]
}
},
"size": 5
}'
1
2
3
4
5
6
7
8
9
10
11
12
13
根据时间的日期聚合
GET your_index/_search
{
"size": 0,
"aggs": {
"day": {
"date_histogram": {
"field": "your_field",
"interval": "day"
}
}
}
}