ES入門REST API


在ES中存在4種數據對象,分別是 index  ,  type ,  document  , field .   其跟我們熟悉的關系型數據庫得二維表得對應關系為:

index -> table表 ,  document -> row行 , field -> column列, type無對應得關系,它為index得一種邏輯分類.

ES使用 index 為單元來組織數據(document),一個index可以有一個或者多個type,document為最基礎得數據單元,

document中得信息存儲在字段(field)中.

下面梳理出幾個入門級得簡單得curl簡單使用。

1、查看集群情況網頁地址: 

http://master_node_ip:9100/

2、查看集群得健康狀態:

curl -XGET 'localhost:9200/_cat/health?v'

3、查看集群的節點數目和主節點等信息

curl -XGET localhost:9200/_cat/nodes?v'

4、新建一個索引

curl -XPUT 'localhost:9200/jim/?pretty'

5、查看索引得setting及mapping

curl -XGET 'localhost:9200/jim/_settings?pretty'
curl -XGET 'localhost:9200/jim/_mappings?pretty'

6、添加document

curl -XPUT 'localhost:9200/jim/firstme/1?pretty' -d '{
    "firstname":        "LoadL",
    "lastname":         "Lee",
    "age":              27,
    "on_line_date":    "2018-11-11",
    "hometown":         "DB",
    "nowlive":          "BeiJing",
    "married":          false,
    "about":            "I love Beijing Opera"
}'

7、查看是否存在某個document

curl -i -XHEAD 'localhost:9200/jim/firstme/1'
返回200為存在,返回404為不存在

8、獲取一個document

curl -XGET 'localhost:9200/jim/firstme/1?pretty'
"_source"字段中存儲的是Document內部的數據

9、更新document

curl -XPUT 'localhost:9200/jim/firstme/1?pretty' -d '{
    "firstname":        "LoadL",
    "lastname":         "Lee",
    "age":              27,
    "on_line_date":    "2018-11-11",
    "hometown":         "HeiLongJiang",
    "nowlive":          "BeiJing",
    "married":          false,
    "about":            "I love Beijing Opera"
}'
更新完成后,該document得version會加1

10、刪除document

curl -XDELETE 'localhost:9200/jim/firstme/1?pretty'

11、刪除index

curl -XDELETE 'localhost:9200/jim/?pretty'

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM