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"
六、新增数据
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]"}'
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]"}'
七、删除数据
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"