#創建索引
a.put創建
curl -XPUT http://localhost:9200/shb01/student/1-d'{"name":"jack","age":30,"info":"Ilove you"}'
返回:{"_index":"shb01","_type":"student","_id":"1","_version":1,"created":true}
執行put后有返回值
_index索引名稱
_type類型名
_version版本號
created:true表示是新創建的。
上面的命令每執行一次version就會加1,-XPUT必須制定id。
b.post創建
curl -XPOST http://localhost:9200/shb01/student -d'{"name":"tom","age":21,"info":"tom"}'
返回:{"_index":"shb01","_type":"student","_id":"AVadzuNgxskBS1Rg2tdp","_version":1,"created":true}
#查看es集群狀態
http://ip:port/_cat/health?v
#集群節點健康查看
http://ip:port/_cat/nodes?v
#查詢所有索引,pretty:格式化
curl -XGET 'localhost:9200/_cat/indices?v&pretty'
#查詢返回最近10條
curl -XPOST 'localhost:9200/logstash-zhifubao-2018.09.18/_search?pretty' -d '{"query": { "match_all": {} },"from": 10,"size": 10}'
#查詢索引狀態
curl -XGET http://localhost:9200/logstash-zhifubao-2018.08.15/_status
#查詢某一個索引
curl -XGET http://localhost:9200/logstash-zhifubao-2018.08.15/message/0ea1b2df-caa4-457c-8cc1-294f5e9284c7/_search?pretty
#根據business_no查詢,多個條件用逗號拼接
curl -XGET http://localhost:9200/logstash-zhifubao-2018.08.15/_search?q=message:0ea1b2df-caa4-457c-8cc1-294f5e9284c7
#根據business_no查詢,只返回特定字段
curl -XGET http://localhost:9200/logstash-zhifubao-2018.08.15/_search?q=message:0ea1b2df-caa4-457c-8cc1-294f5e9284c7?_source=message
#查詢集群狀態
Curl –XGET http://localhost:9200/_cluster/health?pretty
http://localhost:9200/_cluster/health?pretty
#多索引,多類型查詢,分頁查詢,超時
Curl:curl -XGET http://localhost:9200/shb01,shb02/stu,tea/_search?pretty
curl -XGET http://localhost:9200/_all/stu,tea/_search?pretty
#分頁
curl -XGET http://localhost:9200/shb01/stu/_search?size=2&from=0
#更新部分字段
crul –XPUT http:localhost:9200/shb01/student/1/_update?version=1
–d ‘{“doc”:{“name”:”updatename”}
#根據id刪除
curl -XDELETE http://localhost:9200/shb01/student/AVad05EExskBS1Rg2tdq
#刪除所有的索引庫中名稱為tom的文檔
curl -XDELETE http://localhost:9200/_all/_query?q=name:tom
#批處理
a.在/usr/local/下新建t.txt文件,文件內容為
{"index":{"_index":"shb01","_type":"student","_id":"1"}}
{"name":"st01","age":"10","info":"st01"}
{"create":{"_index":"shb100","_type":"student","_id":"2"}}
{"name":"tea01","age":"10","info":"tea01"}
{"delete":{"_index":"shb01","_type":"student","_id":"AVadzuNgxskBS1Rg2tdp"}
{"update":{"_index":"shb02","_type":"tea","_id":"1"}}
{"doc":{"name":"zszszszs"}}
b.執行批處理命令,關鍵字_bulk
curl -XPUThttp://localhost:9200/_bulk --data-binary @/usr/local/t
#_cluster系列
1、查詢設置集群狀態
curl -XGET localhost:9200/_cluster/health?pretty=true
pretty=true表示格式化輸出
level=indices 表示顯示索引狀態
level=shards 表示顯示分片信息
2、curl -XGET localhost:9200/_cluster/stats?pretty=true
顯示集群系統信息,包括CPU JVM等等
3、curl -XGET localhost:9200/_cluster/state?pretty=true
集群的詳細信息。包括節點、分片等。
3、curl -XGET localhost:9200/_cluster/pending_tasks?pretty=true
獲取集群堆積的任務
#索引參數相關
URL 說明
/index/_search 不解釋
/_aliases 獲取或操作索引的別名
/index/
/index/type/ 創建或操作類型
/index/_mapping 創建或操作mapping
/index/_settings 創建或操作設置(number_of_shards是不可更改的)
/index/_open 打開被關閉的索引
/index/_close 關閉索引
/index/_refresh 刷新索引(使新加內容對搜索可見)
/index/_flush
刷新索引
將變動提交到lucene索引文件中
並清空elasticsearch的transaction log,
與refresh的區別需要繼續研究
/index/_optimize 優化segement,個人認為主要是對segement進行合並
/index/_status 獲得索引的狀態信息
/index/_segments 獲得索引的segments的狀態信息
/index/_explain 不執行實際搜索,而返回解釋信息
/index/_analyze 不執行實際搜索,根據輸入的參數進行文本分析
/index/type/id 操作指定文檔,不解釋
/index/type/id/_create 創建一個文檔,如果該文件已經存在,則返回失敗
/index/type/id/_update 更新一個文件,如果改文件不存在,則返回失敗
#集群參數相關
URL 說明
/_cluster/nodes 獲得集群中的節點列表和信息
/_cluster/health 獲得集群信息
/_cluster/state 獲得集群里的所有信息(集群信息、節點信息、mapping信息等)
#Nodes參數相關
URL 說明
/_nodes/process 我主要看file descriptor 這個信息
/_nodes/process/stats 統計信息(內存、CPU能)
/_nodes/jvm 獲得各節點的虛擬機統計和配置信息
/_nodes/jvm/stats 更詳細的虛擬機信息
/_nodes/http 獲得各個節點的http信息(如ip地址)
/_nodes/http/stats 獲得各個節點處理http請求的統計情況
/_nodes/thread_pool
獲得各種類型的線程池
(elasticsearch分別對不同的操作提供不同的線程池)的配置信息
/_nodes/thread_pool/stats 獲得各種類型的線程池的統計信息
以上這些操作和可以通過如
/_nodes/${nodeId}/jvm/stats
/_nodes/${nodeip}/jvm/stats
/_nodes/${nodeattribute}/jvm/stats
的形式針對指定節點的操作。