The REST API

Now that we have our node (and cluster) up and running, the next step is to understand how to communicate with it.

1.Check your cluster, node, and index health, status, and statistics

2.Administer your cluster, node, and index data and metadata

3.Perform CRUD (Create, Read, Update, and Delete) and search operations against your indexes

4.Execute advanced search operations such as paging, sorting, filtering, scripting, aggregations, and many others

Cluster Health

es@qiandu1-yuwencai:~/cluster/elasticsearch-2.3.1$ curl 'localhost:9200/_cat/health?v'
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1460959146 13:59:06 es_cluster green 1 1 0 0 0 0 0 0 - 100.0%

status

  • green, Green means everything is good (cluster is fully functional)
  • yellow, yellow means all data is available but some replicas are not yet allocated (cluster is fully functional)
  • red, Red means some data is not available for whatever reason

List All Nodes

es@qiandu1-yuwencai:~/cluster/elasticsearch-2.3.1$ curl 'localhost:9200/_cat/nodes?v'
host ip heap.percent ram.percent load node.role master name
127.0.0.1 127.0.0.1 7 82 0.01 d * es_node_1

表明集群中只有一个节点,es_node_1

List All Indices

es@qiandu1-yuwencai:~/cluster/elasticsearch-2.3.1$ curl 'localhost:9200/_cat/indices?v'
health status index pri rep docs.count docs.deleted store.size pri.store.size

表明集群中还没有indices

Create an Index

es@qiandu1-yuwencai:~/cluster/elasticsearch-2.3.1$ curl -XPUT 'localhost:9200/customer?pretty'

返回·

{
"acknowledged" : true
}

The first command creates the index named "customer" using the PUT verb. We simply append pretty to the end of the call to tell it to pretty-print the JSON response (if any).

es@qiandu1-yuwencai:~/cluster/elasticsearch-2.3.1$ curl 'localhost:9200/_cat/indices?v'

返回

health status index    pri rep docs.count docs.deleted store.size pri.store.size
yellow open customer 5 1 0 0 650b 650b

The results of the second command tells us that we now have 1 index named customer and it has 5 primary shards and 1 replica (the defaults) and it contains 0 documents in it.

The results of the second command tells us that we now have 1 index named customer and it has 5 primary shards and 1 replica (the defaults) and it contains 0 documents in it.

Status yellow means that some replicas are not (yet) allocated. The reason this happens for this index is because Elasticsearch by default created one replica for this index. Since we only have one node running at the moment, that one replica cannot yet be allocated (for high availability) until a later point in time when another node joins the cluster. Once that replica gets allocated onto a second node, the health status for this index will turn to green.

Index and Query a Document

Let’s now put something into our customer index. Remember previously that in order to index a document, we must tell Elasticsearch which type in the index it should go to.

Let’s index a simple customer document into the customer index, "external" type, with an ID of 1 as follows:

Our JSON document: { "name": "John Doe" }

es@qiandu1-yuwencai:~/cluster/elasticsearch-2.3.1$curl -XPUT 'localhost:9200/customer/external/1?pertty' -d '
{
"name":"John Doe"
}'

返回

{"_index":"customer","_type":"external","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}

From the above, we can see that a new customer document was successfully created inside the customer index and the external type. The document also has an internal id of 1 which we specified at index time.

Retrieve Document

es@qiandu1-yuwencai:~/cluster/elasticsearch-2.3.1$ curl -XGET 'localhost:9200/customer/external/1?pretty'

返回

{
"_index" : "customer",
"_type" : "external",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"name" : "John Doe"
}
}
  • field found:stating that we found a document with the requested ID 1
  • field _source: which returns the full JSON document that we indexed from the previous step.

Delete an Index

es@qiandu1-yuwencai:~/cluster/elasticsearch-2.3.1$ curl -XDELETE 'localhost:9200/customer?pertty'

返回

{"acknowledged":true}

查看索引

es@qiandu1-yuwencai:~/cluster/elasticsearch-2.3.1$ curl 'localhost:9200/_cat/indices?v'

返回

health status index pri rep docs.count docs.deleted store.size pri.store.size

Which means that the index was deleted successfully and we are now back to where we started with nothing in our cluster.

REST API Summary

That pattern can be summarized as follows:

curl -X<REST Verb> <Node>:<Port>/<Index>/<Type>/<ID>

参考资料

【1】

来源: https://www.elastic.co/guide/en/elasticsearch/reference/current/_exploring_your_cluster.html

【2】

来源: https://www.elastic.co/guide/en/elasticsearch/reference/current/_cluster_health.html

【3】

来源: https://www.elastic.co/guide/en/elasticsearch/reference/current/_create_an_index.html

【4】

来源: https://www.elastic.co/guide/en/elasticsearch/reference/current/_index_and_query_a_document.html

ES Docs-2:Exploring ES cluster的更多相关文章

  1. ES系列(五):获取单条数据get处理过程实现

    前面讲的都是些比较大的东西,即框架层面的东西.今天咱们来个轻松点的,只讲一个点:如题,get单条记录的es查询实现. 1. get语义说明 get是用于搜索单条es的数据,是根据主键id查询数据方式. ...

  2. 白日梦的ES笔记三:万字长文 Elasticsearch基础概念统一扫盲

    目录 一.导读 二.彩蛋福利:账号借用 三.ES的Index.Shard及扩容机制 四.ES支持的核心数据类型 4.1.数字类型 4.2.日期类型 4.3.boolean类型 4.4.二进制类型 4. ...

  3. ES系列(一):编译准备与server启动过程解析

    ES作为强大的和流行的搜索引擎服务组件,为我们提供了方便的和高性能的搜索服务.在实际应用中也是用得比较爽,但如果能够更深入一点.虽然网上有许多的文章已经完整说明,ES是如何如何做到高性能,如何做到高可 ...

  4. 建模:通过ES平铺关系型数据库多表的数据

    问:建模要从一个限界上下文中来建模,是否可以简单的把几张表进行笛卡尔乘积方式的平铺? 答:不能,原因之一,数据量会急剧增长:原因之二,这样的平铺是毫无意义的,必须要定义一个维度,在这个维度上根据需求约 ...

  5. 漫画:深入浅出 ES 模块

    本文来自网易云社区. 本文翻译自:ES modules: A cartoon deep-dive ES 模块为 JavaScript 提供了官方标准化的模块系统.然而,这中间经历了一些时间 —— 近 ...

  6. ES新提案:双问号操作符

    摘要: 简单实用的新特性. 原文:ES新提案:双问号操作符 译者:前端小智 本文主要讲Gabriel Isenberg撰写的ES提案"Nullish coalescing for JavaS ...

  7. 2020-07-13:es是去查id再根据id去查数据库这种方式好,还是所有数据都放es,直接去查es好?

    福哥答案2020-07-13: 有人觉得第一种方法好,也有人觉得第二种方法好.如果搜索字段远小于显示字段,比如搜索字段为3个,显示字段有20个,这个时候用第一种方法好.es+hbase,一般这样搭配. ...

  8. es 剩余磁盘空间达到es最小值,添加数据被block

    剩余磁盘空间达到es最小值,添加数据被block PUT _all/_settings {"index.blocks.read_only_allow_delete": null} ...

  9. Android OpenGL ES(一)OpenGL ES介绍

    在学习Android OpenGL ES开发之前,你必须具备Java 语言开发经验和一些Android开发的基本知识,但并不需要有图形开发的经验,本教程也会涉及到一些基本的线性几何知识,如矢量,矩阵运 ...

随机推荐

  1. svn及git使用笔记

    这周发生好几件大事: 谷歌发布SHA-1安全加密碰撞实例 Cloudflare 泄露网络会话中的加密数据 linux内核漏洞 CVE-2017-6074 加密在网络中越来越受关注,目前github的提 ...

  2. 分享知识-快乐自己:Liunx-大数据(Hadoop)初始化环境搭建

    大数据初始化环境搭建: 一):大数据(hadoop)初始化环境搭建 二):大数据(hadoop)环境搭建 三):运行wordcount案例 四):揭秘HDFS 五):揭秘MapReduce 六):揭秘 ...

  3. PyCharm配置过程记录

    也可以通过命令行来上传和下载git bash here 同步最新代码到本地: git fetch git pull 上传文件至git仓库: git commit git push 安装第三方模块方式 ...

  4. poj-2478 Farey Sequence(dp,欧拉函数)

    题目链接: Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14230   Accepted:  ...

  5. linux命令学习笔记(48):watch命令

    watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测 一个命令的运行结果,省得你一遍遍的手动运行.在Linux下,watch是周期性的执行下 ...

  6. FFmpeg 基本用法--此文转载,作为笔记

    v  容器(Container) v  容器就是一种文件(封装)格式,比如flv.mkv.ts.mp4.rmvb.avi等.包含下面5种流以及文件头信息. v  流(Stream) v  是一种视频数 ...

  7. 如何生成HLS协议的M3U8文件

    什么是HLS协议: HLS(Http Live Streaming)是由Apple公司定义的用于实时流传输的协议,HLS基于HTTP协议实现,传输内容包括两部分,一是M3U8描述文件,二是TS媒体文件 ...

  8. noip模拟赛 #3

    T1 给一个环,每个点有一个权值,把环分成三段,求最小的那段的最大值 sol:暴力 二分答案,chk就是把环搞成三倍链,每次枚举起点,后面三个切割点都可以二分找 然后就Rua过去了 //yyc wen ...

  9. ACM学习历程—FZU2148 Moon Game(计算几何)

    Moon Game Description Fat brother and Maze are playing a kind of special (hentai) game in the clearl ...

  10. 【ML】关于神经网络优化问题的随笔记

    1. 为什么不去试着最大化正确分类的图像数量而使用二次代价函数? 在神经网络中,被正确分类的图像数量所关于权重和偏置的函数并不是一个平滑的函数.大多数情况下,对权重和偏执做出的微小变动完全不会影响被正 ...