#建立索引
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。node
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}app
#查看es集羣狀態
http://ip:port/_cat/health?vcurl
#集羣節點健康查看
http://ip:port/_cat/nodes?v jvm
#查詢全部索引,pretty:格式化
curl -XGET 'localhost:9200/_cat/indices?v&pretty'elasticsearch
#查詢返回最近10條
curl -XPOST 'localhost:9200/logstash-zhifubao-2018.09.18/_search?pretty' -d '{"query": { "match_all": {} },"from": 10,"size": 10}'post
#查詢索引狀態
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?prettyurl
#根據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系列
一、查詢設置集羣狀態
curl -XGET localhost:9200/_cluster/health?pretty=true
pretty=true表示格式化輸出
level=indices 表示顯示索引狀態
level=shards 表示顯示分片信息
二、curl -XGET localhost:9200/_cluster/stats?pretty=true
顯示集羣系統信息,包括CPU JVM等等
三、curl -XGET localhost:9200/_cluster/state?pretty=true
集羣的詳細信息。包括節點、分片等。
三、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的形式針對指定節點的操做。