- 查詢ES下所有的索引
- curl '192.168.160.128:9200/_cat/indices'
- 刪除指定的索引
- curl -XDELETE '192.168.160.128:9200/index1'
- 刪除指定的多個索引
- curl -XDELETE '192.168.160.128:9200/index1,index2'
- 刪除所有索引
- curl -XDELETE '192.168.160.128:9200/_all'
- 創建索引
- curl '192.168.160.128:9200/_cat/indices'
- 創建索引並指定分片和副本數量
- curl -H "Content-Type:application/json" -XPUT '192.168.160.128:9200/index2' -d '{"settings":{"number_of_shards":12,"number_of_replicas":1}}'
- 創建索引並指定配置以及映射
- curl -H "Content-Type:application/json" -XPUT '192.168.160.128:9200/index3?pretty' -d '{"settings":{"number_of_shards":12,"number_of_replicas":1},"mappings":{"type1":{"properties":{"name":{"type":"keyword"}}}}}'
- 創建索引並指定配置、映射以及別名
- curl -H "Content-Type:application/json" -XPUT '192.168.160.128:9200/index4?pretty' -d '{"settings":{"number_of_shards":12,"number_of_replicas":1},"mappings":{"type1":{"properties":{"name":{"type":"keyword"}}}},"aliases":{"index4_v1":{},"index4_v2":{}}}'
- 使用_aliases爲索引添加別名
- curl -XPOST '192.168.160.128:9200/_aliases' -H "Content-Type:application/json" -d '{"actions":[{"add":{"index":"index1","alias":"index1_v1"}}]}'
- 使用_alias爲索引添加別名
- curl '192.168.16-XPUT '192.168.160.128:9200/index1/_alias/index1_v3'
- 查詢索引的所有別名
- curl '192.168.160.128:9200/index1/_alias/*'
- 查詢索引的映射
- curl '192.168.160.128:9200/index1/_mapping?pretty'
- 爲索引創建映射
- curl -H "Content-Type:application/json" '192.168.160.128:9200/index1/_mapping/type1' -d '{"type1":{"properties":{"name":{"type":"keyword"}}}}'
- 向索引中插入數據
- curl -H "Content-Type:application/json" -XPOST '192.168.160.128:9200/index1/type1/1?pretty' -d '{"name":"zhangsan","age":"22"}'
- 使用_bulk批量插入數據
-
- curl -H "Content-Type:application/json" -XPOST '192.168.160.128:9200/index1/type1/_bulk?pretty' --data-binary @test.json
-
"index":{"_id":"3"}}
{"name":"wangwu","age":"33"}
{"index":{"_id":"4"}}
{"name":"zhangliu","age":"35"}
//最後一行應該空出
-
- curl -H "Content-Type:application/json" -XPOST '192.168.160.128:9200/index1/type1/_bulk?pretty' -d '{"index":{"_id":"3"}}{"name":"wangwu","age":"33"}{"index":{"_id":"4"}}{"name":"zhangliu","age":"35"}'
- 報錯,The bulk request must be terminated by a newline [\n]。-d中每行都需要換行,類似於json文檔
- curl -H "Content-Type:application/json" -XPOST '192.168.160.128:9200/index1/type1/_bulk?pretty' -d '{"index":{"_id":"3"}}{"name":"wangwu","age":"33"}{"index":{"_id":"4"}}{"name":"zhangliu","age":"35"}'
-
- 查詢指定id的數據
-
- curl '192.168.160.128:9200/index1/type1/1?pretty'
-
- 查詢指定索引指定類型下所有數據
- curl '192.168.160.128:9200/index1/type1/_search?pretty'
- 修改指定id的文檔
- curl -H "Content-Type:application/json" -XPOST '192.168.160.128:9200/index1/type1/4/_update?pretty' -d '{"doc":{"tags":["2","3"]}}'
- 查詢時在URL中指定搜索請求基本模塊from、size、sort等
- curl '192.168.160.128:9200/index1/type1/_search?pretty&from=0&size=2&sort=age:asc&_source=age&q=zhangsan'
- 查詢時在JSON請求體中指定搜索請求基本模塊from、size、sort等
- curl -H "Content-Type:application/json" '192.168.160.128:9200/index1/type1/_search?pretty' -d '{"query":{"match_all":{}},"from":0,"size":1,"_source":"name"}'
- 使用過濾器查詢
- curl -H "Content-Type:application/json" '192.168.160.128:9200/index1/type1/_search?pretty' -d '{"query":{"bool":{"filter":{"term":{"age":"33"}}}}}'
Elasticsearch實戰系列(八)--ES常見操作
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.