ES常用命令(2)

ElasticSearch 操作

一、索引创建

  • 创建索引
curl -X PUT -H 'Content-Type: application/json' "http://localhost:9200/message_20200428" -d '{"settings":{"number_of_shards":4,"number_of_replicas":1}}'
  • 创建映射
curl -XPUT 'http://localhost:9200/message_20200428/_mapping/_doc?pretty' -d '{"properties":{"channelNo":{"type":"integer"},"deviceId":{"type":"keyword"},"deviceName":{"type":"keyword"},"endTime":{"type":"long"},"eventId":{"type":"keyword"},"eventType":{"type":"integer"},"id":{"type":"keyword"},"region":{"type":"keyword"},"unifiedId":{"type":"keyword"},"hasService":{"type":"integer"},"productKey":{"type":"keyword"},"token":{"type":"keyword"},"startTime":{"type":"long"},"uid":{"type":"long"},"expireTime":{"type":"long"}}}' 
  • 创建索引和映射
curl -X PUT -H 'Content-Type: application/json' 'http://localhost:9200/message_20200429'  -d  '{"settings":{"number_of_shards":4,"number_of_replicas":1},"mappings":{"properties":{"channelNo":{"type":"integer"},"deviceId":{"type":"keyword"},"deviceName":{"type":"keyword"},"endTime":{"type":"long"},"eventId":{"type":"keyword"},"eventType":{"type":"integer"},"id":{"type":"keyword"},"region":{"type":"keyword"},"unifiedId":{"type":"keyword"},"hasService":{"type":"integer"},"productKey":{"type":"keyword"},"token":{"type":"keyword"},"startTime":{"type":"long"},"uid":{"type":"long"},"expireTime":{"type":"long"}}}}'

二、删除索引

  • 删除指定索引
curl -X DELETE "http://localhost:9200/message_20200428"
  • 模糊删除索引
curl -X DELETE "http://localhost:9200/message_*"
  • 条件删除数据
curl -X POST -H 'Content-Type: application/json' "http://localhost:9200/message_*/_delete_by_query" -d '{"query":{"bool":{"must":[{"range":{"expireTime":{"lt":"1587994320316"}}}]}}}'

三、查询索引

  • 查询指定索引
curl -X GET "http://localhost:9200/message_20200428"
  • 模糊查询索引
curl -X GET "http://localhost:9200/message_*"

四、打开索引

  • 开启指定索引
curl -X POST "http://localhost:9200/message_20200428/_open"
  • 模糊开启索引
curl -X POST "http://localhost:9200/message_*/_open"

五、关闭索引

  • 关闭指定索引
curl -X POST "http://localhost:9200/message_20200428/_close"
  • 模糊关闭索引
curl -X POST "http://localhost:9200/message_*/_close"

六、新增数据

  • elasticsearch id新增
curl -X POST -H 'Content-Type: application/json' "http://localhost:9200/message_202005/_doc/" -d '{"channelNo":0,"createTime":1588142769135,"deviceId":"30cc600955b643888b4b876281920966","endTime":1588142769135,"eventId":"300001","eventType":1,"expireTime":1588747570647,"hasService":1,"productKey":"18b","region":"bj_hw","startTime":1588142769135,"token":"22222222222","uid":10000001,"unifiedId":"[email protected]"}'
  • 指定id新增
curl -X POST -H 'Content-Type: application/json' "http://localhost:9200/message_202005/_doc/30cc600955b8b4b876281920966" -d '{"channelNo":0,"createTime":1588142769135,"deviceId":"30cc600955b643888b4b876281920966","endTime":1588142769135,"eventId":"300001","eventType":1,"expireTime":1588747570647,"hasService":1,"id":"30cc600955b643888b4b876281920966","productKey":"18b","region":"bj_hw","startTime":1588142769135,"token":"22222222222","uid":10000001,"unifiedId":"[email protected]"}'

七、删除数据

  • 指定id删除
curl -X DELETE  "http://localhost:9200/message_20200506/_doc/3162f4f7a5754027bc523b58478a9ae1"
  • 条件删除
curl -X POST -H 'Content-Type: application/json' "http://localhost:9200/message_20200427/_delete_by_query" -d '{"query":{"bool":{"must":[{"term":{"_id":"8txvunEB9TUMVBYP-ank"}}]}}}'

八、磁盘释放

  • 是否已删除数据占用的磁盘
curl -X POST  "http://localhost:9200/_forcemerge/_forcemerge?only_expunge_deletes=true"

你可能感兴趣的:(ES常用命令(2))