码迷,mamicode.com
首页 > Windows程序 > 详细

ES入门REST API

时间:2018-11-12 19:57:33      阅读:464      评论:0      收藏:0      [点我收藏+]

标签:local   维表   about   col   json   字段   opera   div   有一个   

在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‘

 

ES入门REST API

标签:local   维表   about   col   json   字段   opera   div   有一个   

原文地址:https://www.cnblogs.com/loadL/p/simple_es_curl.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!