elasticsearch 簡單操作
阿新 • • 發佈:2018-12-20
1 查詢健康狀態
http://192.168.34.3:9200/_cluster/health?pretty
{ "cluster_name" : "elasticsearch", "status" : "yellow", "timed_out" : false, "number_of_nodes" : 1, "number_of_data_nodes" : 1, "active_primary_shards" : 10, "active_shards" : 10, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 10, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 50.0 }
2 檢視節點列表
http://192.168.34.3:9200/_cat/nodes?v
3 檢視索引列表
http://192.168.34.3:9200/_cat/indices?v
4 新增索引
[[email protected] /]# curl -XPUT '192.168.34.3:9200/img?pretty'
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "img"
}
[[email protected] /]#
5 刪除索引
[[email protected] /]# curl -XDELETE '192.168.34.3:9200/img?pretty'
{
"acknowledged" : true
}
[[email protected] /]#
6 新增資料
curl -XPUT -H "Content-Type: application/json" 'http://192.168.34.3:9200/test/demo/1?pretty' -d ' { "titleName":"明星桌布", "titleUrl":"http://www.5442.com/mingxing/index.html", "flag":"2", "startPage":"157", "endPage":"158" }
7 查詢資料 查詢 test索引庫下 型別為demo id 為1的資料(由於編碼不統一出現亂碼)
[[email protected] 0]# curl -XGET '192.168.34.3:9200/test/demo/1'
{"_index":"test","_type":"demo","_id":"1","_version":2,"found":true,"_source":{
"titleName":"駘澹綰?,
"titleUrl":"http://www.5442.com/mingxing/index.html",
"flag":"2",
"startPage":"157",
"endPage":"158",
"name":"寮犱?"
}
8 搜尋 查詢索引庫為test 條件欄位titleName 模糊匹配明的資訊
curl -XGET 'http://192.168.34.3:9200/test/_search?q=titleName:明*'
9 提供一個postman的下載地址方便進行簡單測試
連結:https://pan.baidu.com/s/1AemNf-3xvS7HKxjFkd9jSA
提取碼:jihu
10 官網查詢api地址
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-filtered-query.html