日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Elasticsearch CURL命令

發布時間:2024/9/19 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Elasticsearch CURL命令 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、查看集群狀態

curl "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/_cat/health?v"

提示:綠色表示一切正常, 黃色表示所有的數據可用但是部分副本還沒有分配,紅色表示部分數據因為某些原因不可用

2、獲取集群節點列表

curl "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/_cat/nodes?v"

3、查看所有index

curl -XGET "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/_cat/indices?v"

4、查詢所有的index包含其所有的type

curl -XGET "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/_mapping?pretty=true"

5、查詢某個index下的所有type

curl -XGET "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/_mapping?pretty=true"

6、查詢某個index的所有數據

curl -XGET "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/test/_search?pretty=true"

7、查詢index下某個type類型的數據

curl '10.18.37.223:9200/test/test_topic/_search?pretty=true'

其中:根據規劃,Elastic 6.x 版只允許每個 Index 包含一個 Type,7.x 版將會徹底移
除 Type, index=test type=test_topic 注意自己使用的版本

8、查詢index下某個type下id確定的數據

curl '10.18.37.223:9200/test/test_topic/3525?pretty=true' index = test type= test_topic id = 3525

9、和sql一樣的查詢數據

curl "10.18.37.223:9200/test/_search" -d' { "query": { "match_all": {} }, "_source": ["account_number", "balance"], "sort": { "balance": { "order": "desc" }, "from": 10, "size": 10 } '

注:-d之后的內容使用回車輸入,不能使用換行符,es不能識別
query:里面為查詢條件此處為全部,不做限制,_source:為要顯示的那些字段
sort:為排序字段 from為從第10條開始,size:取10條
除此之外還有:布爾匹配,or匹配。包含匹配。范圍匹配。更多查詢請去官網查看:

官網查詢API地址

10、創建索引(index)

curl -X PUT '10.18.37.223:9200/test?pretty' OR curl -X PUT '10.18.37.223:9200/test'

創建一個名為test的索引
注:索引只能是小寫,不能以下劃線開頭,也不能包含逗號
如果沒有明確指定索引數據的ID,那么es會自動生成一個隨機的ID,需要使用POST參數

11、往index里面插入數據

curl -X PUT '10.18.37.223:9200/test/test_zhang/1?pretty' -d ' {"name":"tom","age":18}'

提示:往es中插入index=test,type=test_zhang id = 1的數據為
{"name":"tom","age":18}的數據。
-X POST也即可

12、修改數據

curl -X PUT '10.18.37.223:9200/test/test_zhang/1?pretty' -d '{"name":"pete","age":20}'

注:修改 index = test type=test_zhang id = 1 數據: {"name":"tom","age":18}
為{"name":"pete","age":20} 成功之后執行查看數據命令可看到最新數據,且
version 會增加一個版本

13、更新數據同時新增數據,在一個index,type中

curl -X POST '10.18.37.223:9200/test/test_zhang/1/_update?pretty' -d '{"doc":{"name":"Alice","age":18,"addr":"beijing"}}'

注:修改了名字,年齡,同時新增了字段addr=beijing

14、利用script更新數據

curl -X POST '10.18.37.223:9200/test/test_zhang/1/_update?pretty' -d '{"script": "ctx._source.age += 5"}'

注:將年齡加5
從ES 1.4.3以后, inline script默認是被禁止的
要打開, 需要在config/elasticsearch.yml中添加如下配置:
script.inline:true
script.indexed:true 然后重啟 (如果是集群模式:需要每個節點都添加 然后重啟)

15、刪除記錄

curl -X DELETE '10.18.37.223:9200/test/test_zhang/1'

注:刪除index = test type = test_zhang id = 1 的數據

16、刪除index

curl -X DELETE '10.18.37.223:9200/test'

刪除index=test的數據

17、批量操作

curl -X POST '10.18.37.223:9200/test/test_zhang/_bulk?pretty' -d ' {"index":{"_id":"2"}} {"name":"zhangsan","age":12} {"index":{"_id":"3"}} {"name":"lisi"} '

注:在index = test type = test_zhang下
新增id= 2 和 id=3 的兩條數據

curl -X POST '10.18.37.223:9200/test/test_zhang/_bulk?pretty' -d ' {"update":{"_id":"2"}} {"doc":{"name":"wangwu"}} {"delete":{"_id":"3"}}'

注: 修改id = 2 的數據 并且同時刪除掉id=3的數據
在index = test type = test_zhang下

18、根據條件刪除

curl -X POST "10.18.37.223:9200/test/_delete_by_query" -d' { "query": { "match": { "name": "pete" } } }'

注: 使用es的_delete_by_query,此插件在es2.0版本以后被移除掉,要使用此命令。
需要自己安裝_delete_by_query插件:
在es安裝目錄下。bin目錄下,執行:
./plugin install delete-by-query 安裝插件
如果是集群模式,則每個節點都需要安裝然后重啟


?

總結

以上是生活随笔為你收集整理的Elasticsearch CURL命令的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。