使用curl命令操作elasticsearch

來源:互聯網
上載者:User

標籤:

使用curl命令操作elasticsearch大岩不燦 發表於 2015年4月25日 瀏覽 7,426 次

第一:_cat系列
_cat系列提供了一系列查詢elasticsearch叢集狀態的介面。你可以通過執行
curl -XGET localhost:9200/_cat
擷取所有_cat系列的操作
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
你也可以後面加一個v,讓輸出內容表格顯示表頭,舉例

name       component        version type urlPrometheus analysis-mmseg   NA      jPrometheus analysis-pinyin  NA      jPrometheus analysis-ik      NA      jPrometheus analysis-ik      NA      jPrometheus analysis-smartcn 2.1.0   jPrometheus segmentspy       NA      s    /_plugin/segmentspy/Prometheus head             NA      s    /_plugin/head/Prometheus bigdesk          NA      s    /_plugin/bigdesk/Xandu      analysis-ik      NA      jXandu      analysis-pinyin  NA      jXandu      analysis-mmseg   NA      jXandu      analysis-smartcn 2.1.0   jXandu      head             NA      s    /_plugin/head/Xandu      bigdesk          NA      s    /_plugin/bigdesk/Onyxx      analysis-ik      NA      jOnyxx      analysis-mmseg   NA      jOnyxx      analysis-smartcn 2.1.0   jOnyxx      analysis-pinyin  NA      jOnyxx      head             NA      s    /_plugin/head/Onyxx      bigdesk          NA      s    /_plugin/bigdesk/

第二:_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
擷取叢集堆積的任務
3、修改叢集配置
舉例:

curl -XPUT localhost:9200/_cluster/settings -d ‘{    "persistent" : {        "discovery.zen.minimum_master_nodes" : 2    }}‘

transient 表示臨時的,persistent表示永久的
4、curl -XPOST ‘localhost:9200/_cluster/reroute’ -d ‘xxxxxx’
對shard的手動控制,參考http://zhaoyanblog.com/archives/687.html
5、關閉節點
關閉指定192.168.1.1節點
curl -XPOST ‘http://192.168.1.1:9200/_cluster/nodes/_local/_shutdown’
curl -XPOST ‘http://localhost:9200/_cluster/nodes/192.168.1.1/_shutdown’
關閉主節點
curl -XPOST ‘http://localhost:9200/_cluster/nodes/_master/_shutdown’
關閉整個叢集
$ curl -XPOST ‘http://localhost:9200/_shutdown?delay=10s’
$ curl -XPOST ‘http://localhost:9200/_cluster/nodes/_shutdown’
$ curl -XPOST ‘http://localhost:9200/_cluster/nodes/_all/_shutdown’
delay=10s表示延遲10秒關閉

第三:_nodes系列
1、查詢節點的狀態
curl -XGET ‘http://localhost:9200/_nodes/stats?pretty=true’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2/stats?pretty=true’
curl -XGET ‘http://localhost:9200/_nodes/process’
curl -XGET ‘http://localhost:9200/_nodes/_all/process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/jvm,process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/info/jvm,process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/_all
curl -XGET ‘http://localhost:9200/_nodes/hot_threads

第四:索引操作

1、擷取索引
curl -XGET ‘http://localhost:9200/{index}/{type}/{id}’
2、索引資料
curl -XPOST ‘http://localhost:9200/{index}/{type}/{id}’ -d‘{“a”:”avalue”,”b”:”bvalue”}’
3、刪除索引
curl -XDELETE ‘http://localhost:9200/{index}/{type}/{id}’
4、設定mapping

curl -XPUT http://localhost:9200/{index}/{type}/_mapping -d ‘{  "{type}" : {"properties" : {  "date" : {"type" : "long"  },  "name" : {"type" : "string","index" : "not_analyzed"  },  "status" : {"type" : "integer"  },  "type" : {"type" : "integer"  }}  }}‘

5、擷取mapping
curl -XGET http://localhost:9200/{index}/{type}/_mapping
6、搜尋

curl -XGET ‘http://localhost:9200/{index}/{type}/_search‘ -d ‘{    "query" : {        "term" : { "user" : "kimchy" } //查所有 "match_all": {}    },"sort" : [{ "age" : {"order" : "asc"}},{ "name" : "desc" } ],"from":0,"size":100}curl -XGET ‘http://localhost:9200/{index}/{type}/_search‘ -d ‘{    "filter": {"and":{"filters":[{"term":{"age":"123"}},{"term":{"name":"張三"}}]},"sort" : [{ "age" : {"order" : "asc"}},{ "name" : "desc" } ],"from":0,"size":100}

使用curl命令操作elasticsearch

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.