ES数据库相关操作

##es数据库的应用

最近的项目中,es集群分三个节点安装,一个主节点,两个副节点。

目前我们的使用场景主要是存储流量日志数据,针对不同的日志类型,索引按天创建,例如skyeye-tcpflow-20191001、skyeye-udpflow-20191002。

es分片的作用,为了让所有数据均衡的存储在集群各个节点的分片中,能够快速、安全、稳定的搜索数据。

##ES基本操作
一、创建索引
自定义创建:
curl -XPUT “localhost:9200/test?pretty” -d’{“settings”:{“index”:{“number_of_shards”:3,“number_of_replicas”:2}}}

根据模板创建索引:
查询集群中存在的模板
curl -sXGET localhost:9200/_template?pretty |grep noah_fw(模板名)
根据模板名创建索引
curl -XPUT localhost:9200/noah_fw_20201102

二、集群查询操作
集群状态查询:
1、curl -sXGET localhost:9200/_cat/health?pretty
2、curl -sXGET localhost:9200/_cluster/health?pretty

集群节点查询:
curl -sXGET localhost:9200/_cat/nodes?v

集群节点属性查询:
curl -sXGET localhost:9200/_cat/nodeattrs?v

集群所有索引分片相关信息查询:
curl -sXGET localhost:9200/_cat/shards?v

集群设置查询:
curl -sXGET localhost:9200/_cluster/settings?pretty

三、索引查询操作
查询所有的索引:
curl -sXGET localhost:9200/_cat/indices?v

查询单个索引:
curl -sXGET localhost:9200/_cat/indices?v |grep 索引名

查询索引的具体信息:
curl -sXGET localhost:9200/索引名?pretty

查询索引的配置:
curl -sXGET localhost:9200/索引名/_settings?pretty

查询索引的分片:
curl -sXGET localhost:9200/_cat/shards/索引名?pretty

查询集群所有索引的doc数量:
curl -sXGET localhost:9200/_cat/count?v

四、查询索引匹配数据
1、查询索引数据(显示倒叙10条):
curl -sXGET localhost:9200/索引名/_search?pretty

2、查询索引倒叙1000条数据:
curl -sXGET localhost:9200/索引名/_search?pretty -d’{
“query”:{
“match_all”:{}
},
“size”:1000
}’

3、查询索引匹配数据:
curl -sXGET localhost:9200/索引名/_search?pretty -d ’
{
“query”:{
“match”:{ “dip”:"192.168.59.137"查询字段
}
},
“size”:1000
}’

4查询索引匹配数据 - multi_match
curl -sXGET localhost:9200/索引名/_search?pretty -d ’
{
“query”:{
“bool”:{
“must”:[
{“match”:{“dip”:“220.181.12.100”}},查询字段
{“match”:{“sip”:“10.95.43.12”}}查询字段
]
}
}
}’

五、修改操作
1、关闭索引
curl -XPOST localhost:9200/_close

2、开启索引
curl -XPOST localhost:9200/-open

3、关闭指定索引
curl -XPOST localhost:9200/索引名/_close

4、开启指定索引
curl -XPOST localhost:9200/索引名/_open

5、修改每个节点可同时恢复的分片个数
Curl –XPUT localhost:9200/_cluster/settings –d ’
{“transient”:{“cluster.routing.allocation.node_concurrent_recoveries”:“60”}}

六、删除索引
1、删除单个索引
curl -XDELETE localhost:9200/索引名

2、删除所有索引
curl -sXPUT “http://localhost:9200/_cluster/settings” -d
'{“persistent”:{“action.destructive_requires_name”:false}}‘

curl -XDELETE localhost:9200/_all

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值