ElasticSearch
ElasticSearch
ElasticSearch官网
https://www.elastic.co/cn/elasticsearch/
Window安装ElasticSearch
下载elasticsearch-7.15.2-windows-x86_64.zip并解压,启动bin/elasticsearch.bat,访问http://localhost:9200/
下载kibana-7.15.2-windows-x86_64.zip并解压,启动bin/kibana.bat,访问http://localhost:5601/
Window修改ElasticSearch内存
进入D:\elasticsearch-7.15.2\bin,elasticsearch-service.bat manager
ElasticSearch默认一次最多查询1W条记录,可修改如下参数调整
curl -XPUT http://localhost:9200/sys_region/_settings -d '{"index.max_result_window" :"1000000"}'
curl -XGET http://localhost:9200/sys_region/_settings
ElasticSearch监控工具
查看所有索引
curl -X GET http://localhost:9200/_cat/indices
删除索引
curl -X DELETE http://localhost:9200/sys_region
kibana删除ES索引
DELETE /sys_region
查看存储空间
curl -X GET http://localhost:9200/_cat/shards?v
查看索引下数据量
http://localhost:9200/_cat/count/sys_region
ElasticSearch操作符
gt: greater than 大于
gte: greater than or equal 大于等于
lt: less than 小于
lte: less than or equal 小于等于
统计数量
GET /dl_hist_order_pay/_count
{
}
根据条件统计数量
GET /dl_hist_order_pay/_count
{
"query":{
"bool":{
"must":[
{
"range":{
"businessDateLong":{
"gte":1606752000000,
"lte":1606838399000
}
}
},
{
"term":{
"card_no":"379388XXXXXX008"
}
}
]
}
}
}
分组查询
{
"query":{
"match_all":{
}
},
"aggregations":{
"cardno":{
"terms":{
"field":"card_no",
"size":30
}
}
}
}
分组查询
GET /dl_hist_order_pay/_search
{
"query":{
"bool":{
"must":[
{
"range":{
"businessDateLong":{
"gte":1606752000000,
"lte":1606838399000
}
}
},
{
"term":{
"card_no":"379388XXXXXX008"
}
}
]
}
},
"aggregations":{
"cardno":{
"terms":{
"field":"card_no",
"size":30
}
}
}
}
查询gross_amt在0-6之间,按branch_code分组
{
"query":{
"range":{
"gross_amt":{
"from":0,
"to":6,
"include_lower":false,
"include_upper":false
}
}
},
"aggregations":{
"cardno":{
"terms":{
"field":"branch_code",
"size":30111
}
}
}
}
size:0 只获取统计之后的结果,统计用到的原始数据不显示
GET /dl_hist_order/_search
{
"size":0,
"query":{
"bool":{
"must":[
{
"range":{
"businessDateLong":{
"gte":1601481600000,
"lte":1601481600000
}
}
},
{
"range":{
"gross_amt":{
"gt":0,
"lt":1
}
}
}
]
}
},
"aggs":{
"branch_code":{
"terms":{
"field":"branch_code.keyword",
"size":30111
},
"aggs":{
"grand_total":{
"sum":{
"field":"grand_total"
}
},
"uid":{
"cardinality":{
"field":"uid"
}
},
"order_no":{
"cardinality":{
"field":"order_no"
}
}
}
}
}
}
多字段分组
{
"size":0,
"aggs":{
"branchCode":{
"terms":{
"field":"branchCode.keyword",
"size":50000
},
"aggs":{
"cashierid":{
"terms":{
"field":"cashierid.keyword",
"size":50000
}
}
}
}
}
}
查看某字段值为空或不存在
GET dl_hist_order/_count
{
"query":{
"bool":{
"must_not":[
{
"exists":{
"field":"branch_code_5"
}
}
]
}
}
}
删除数据
POST dl_hist_order/_delete_by_query
{
"query":{
"bool":{
"must":[
{
"term":{
"businessDateLong":"1636214400000"
}
}
]
}
}
}
Mac安装ElasticSearch
brew tap elastic/tap
brew install elastic/tap/elasticsearch-full
brew services start elastic/tap/elasticsearch-full
启动ElasticSearch:
elasticsearch
下载并解压elasticsearch-head
cd elasticsearch-head
npm install
npm install grunt --save
cd elasticsearch-head/node_modules/grunt/bin,执行grunt server &
查找并修改es,sudo find / -name "elasticsearch.yml",并重启es