日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Elasticsearch CURL命令

發(fā)布時(shí)間:2024/9/19 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Elasticsearch CURL命令 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、查看集群狀態(tài)

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

提示:綠色表示一切正常, 黃色表示所有的數(shù)據(jù)可用但是部分副本還沒有分配,紅色表示部分?jǐn)?shù)據(jù)因?yàn)槟承┰虿豢捎?/p>

2、獲取集群節(jié)點(diǎn)列表

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、查詢某個(gè)index下的所有type

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

6、查詢某個(gè)index的所有數(shù)據(jù)

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

7、查詢index下某個(gè)type類型的數(shù)據(jù)

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

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

8、查詢index下某個(gè)type下id確定的數(shù)據(jù)

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

9、和sql一樣的查詢數(shù)據(jù)

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之后的內(nèi)容使用回車輸入,不能使用換行符,es不能識(shí)別
query:里面為查詢條件此處為全部,不做限制,_source:為要顯示的那些字段
sort:為排序字段 from為從第10條開始,size:取10條
除此之外還有:布爾匹配,or匹配。包含匹配。范圍匹配。更多查詢請(qǐng)去官網(wǎng)查看:

官網(wǎng)查詢API地址

10、創(chuàng)建索引(index)

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

創(chuàng)建一個(gè)名為test的索引
注:索引只能是小寫,不能以下劃線開頭,也不能包含逗號(hào)
如果沒有明確指定索引數(shù)據(jù)的ID,那么es會(huì)自動(dòng)生成一個(gè)隨機(jī)的ID,需要使用POST參數(shù)

11、往index里面插入數(shù)據(jù)

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的數(shù)據(jù)為
{"name":"tom","age":18}的數(shù)據(jù)。
-X POST也即可

12、修改數(shù)據(jù)

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 數(shù)據(jù): {"name":"tom","age":18}
為{"name":"pete","age":20} 成功之后執(zhí)行查看數(shù)據(jù)命令可看到最新數(shù)據(jù),且
version 會(huì)增加一個(gè)版本

13、更新數(shù)據(jù)同時(shí)新增數(shù)據(jù),在一個(gè)index,type中

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

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

14、利用script更新數(shù)據(jù)

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默認(rèn)是被禁止的
要打開, 需要在config/elasticsearch.yml中添加如下配置:
script.inline:true
script.indexed:true 然后重啟 (如果是集群模式:需要每個(gè)節(jié)點(diǎn)都添加 然后重啟)

15、刪除記錄

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

注:刪除index = test type = test_zhang id = 1 的數(shù)據(jù)

16、刪除index

curl -X DELETE '10.18.37.223:9200/test'

刪除index=test的數(shù)據(jù)

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 的兩條數(shù)據(jù)

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 的數(shù)據(jù) 并且同時(shí)刪除掉id=3的數(shù)據(jù)
在index = test type = test_zhang下

18、根據(jù)條件刪除

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目錄下,執(zhí)行:
./plugin install delete-by-query 安裝插件
如果是集群模式,則每個(gè)節(jié)點(diǎn)都需要安裝然后重啟


?

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。