Version

直接对localhost:9200发出一个get请求

{
"name": "WqeJVip",
"cluster_name": "elasticsearch",
"cluster_uuid": "BcCJ0AuOTCyD6RYSBCEACA",
"version": {
"number": "6.6.1",
"build_flavor": "default",
"build_type": "zip",
"build_hash": "1fd8f69",
"build_date": "2019-02-13T17:10:04.160291Z",
"build_snapshot": false,
"lucene_version": "7.6.0",
"minimum_wire_compatibility_version": "5.6.0",
"minimum_index_compatibility_version": "5.0.0"
},
"tagline": "You Know, for Search"
}

Setting

GET /_all/_settings HTTP/1.1
Host: localhost:9200
cache-control: no-cache
Postman-Token: 4aa0826c-faaa-48ab-a7f2-569442d0e79d

Cluster Health(A cluster is a collection of one or more nodes (servers) )

https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-cluster-health.html

C:\WINDOWS\system32>curl -X GET "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
:: elasticsearch green - 100.0%

We can see that our cluster named "elasticsearch" is up with a green status.

Whenever we ask for the cluster health, we either get green, yellow, or red.

  • Green - everything is good (cluster is fully functional)
  • Yellow - all data is available but some replicas are not yet allocated (cluster is fully functional)
  • Red - some data is not available for whatever reason (cluster is partially functional)

Note: When a cluster is red, it will continue to serve search requests from the available shards but you will likely need to fix it ASAP since there are unassigned shards.

Also from the above response, we can see a total of 1 node and that we have 0 shards since we have no data in it yet.

Note that since we are using the default cluster name (elasticsearch) and since Elasticsearch uses unicast network discovery by default to find other nodes on the same machine, it is possible that you could accidentally start up more than one node on your computer and have them all join a single cluster. In this scenario, you may see more than 1 node in the above response.

We can also get a list of nodes in our cluster as follows:

curl -X GET "localhost:9200/_cat/nodes?v"

ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1 mdi * WqeJVip

Here, we can see our one node named "WqeJVip", which is the single node that is currently in our cluster.

List All Indices

https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-list-indices.html

Now let’s take a peek at our indices:

curl -X GET "localhost:9200/_cat/indices?v"

And the response:

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

Which simply means we have no indices yet in the cluster.

Create an Index

Now let’s create an index named "customer" and then list all the indexes again:

curl -X PUT "localhost:9200/customer?pretty"
curl -X GET "localhost:9200/_cat/indices?v"

HTTP/1.1 200 OK
Warning: 299 Elasticsearch-6.6.1-1fd8f69 "the default number of shards will change from [5] to [1] in 7.0.0; if you wish to continue using the default of [5] shards, you must manage this on the create index request or with an index template" "Mon, 18 Mar 2019 07:17:24 GMT"
content-type: application/json; charset=UTF-8
content-length: 84

{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "customer"
}

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).

And the response:

health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open customer p6H8gEOdQAWBuSN2HDEjZA .2kb .2kb

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.

You might also notice that the customer index has a yellow health tagged to it. Recall from our previous discussion that 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.

We’ll index a simple customer document into the customer index, with an ID of 1 as follows:

语法是 /index/_doc/id?pretty

PUT /customer/_doc/1?pretty
{
"name": "John Doe"
}

遇到如下错误

{
"error" : {
"root_cause" : [
{
"type" : "cluster_block_exception",
"reason" : "blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"
}
],
"type" : "cluster_block_exception",
"reason" : "blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"
},
"status" : 403
}

问题解决之后,Elasticsearch cluster_block_exception

{
"_index" : "customer",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 2
}

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

It is important to note that Elasticsearch does not require you to explicitly显式地 create an index first before you can index documents into it. In the previous example, Elasticsearch will automatically create the customer index if it didn’t already exist beforehand.

Let’s now retrieve that document that we just indexed:

查询语法是 /index/_doc/id

GET /customer/_doc/1?pretty

And the response:

{
"_index" : "customer",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 2,
"found" : true,
"_source" : {
"name" : "John Doe"
}
}

Nothing out of the ordinary here other than a field, found, stating that we found a document with the requested ID 1 and another field, _source, which returns the full JSON document that we indexed from the previous step

Delete an Index

Now let’s delete the index that we just created and then list all the indexes again:

DELETE /customer?pretty
GET /_cat/indices?v
 

And the response:

health status index uuid 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.

Before we move on, let’s take a closer look again at some of the API commands that we have learned so far:

PUT /customer
PUT /customer/_doc/1
{
"name": "John Doe"
}
GET /customer/_doc/1
DELETE /customer
 

If we study the above commands carefully, we can actually see a pattern of how we access data in Elasticsearch. That pattern can be summarized as follows:

<HTTP Verb> /<Index>/<Type>/<ID>

This REST access pattern is so pervasive普遍的 throughout all the API commands that if you can simply remember it, you will have a good head start at mastering Elasticsearch.

Elasticsearch-->Get Started-->Exploring Your Cluster的更多相关文章

  1. Elasticsearch 搜索模块之Cross Cluster Search(跨集群搜索)

    Cross Cluster Search简介 cross-cluster search功能允许任何节点作为跨多个群集的federated client(联合客户端),与tribe node不同的是cr ...

  2. Elasticsearch 入门 - Exploring Your Cluster

    The REST API Cluster Health ( http://localhost:9200/ ) curl -X GET "localhost:9200/_cat/health? ...

  3. (四)Exploring Your Cluster

    The REST API Now that we have our node (and cluster) up and running, the next step is to understand ...

  4. ES Docs-2:Exploring ES cluster

    The REST API Now that we have our node (and cluster) up and running, the next step is to understand ...

  5. Elasticsearch Configuration 中文版

    ##################### Elasticsearch Configuration Example ##################### # This file contains ...

  6. ElasticSearch配置说明

    配置文件位于%ES_HOME%/config/elasticsearch.yml文件中. cluster.name: elasticsearch 配置集群名称,默认elasticsearch node ...

  7. Elasticsearch学习之入门2

    关于Elasticsearch的几个概念: 1)在Elasticsearch中,文档归属于类型type,而类型归属于索引index,为了方便理解,可以把它们与传统关系型数据库做类比: Relation ...

  8. 搜索引擎 ElasticSearch 之 步步为营2 【基础概念】

    在正式学习 ElasticSearch 之前,首先看一下 ElasticSearch 中的基本概念. 这些概念将在以后的章节中出现多次,所以花15分钟理解一下是非常值得的. 英文好的同学,请直接移步官 ...

  9. Elasticsearch静态集群配置

    这两天需要将ELK中的单节点运行的ES扩展为双节点,查询了下集群配置,百度搜索结果还是一如既往的坑,基本都是各种转帖,以下记录配置静态集群的步骤: * * * <pre><code& ...

  10. elasticsearch单机多实例环境部署

    elasticsearch的功能,主要用在搜索领域,这里,我来研究这个,也是项目需要,为公司开发了一款CMS系统,网站上的搜索栏功能,我打算采用elasticsearch来实现. elasticsea ...

随机推荐

  1. Ubuntu安装mysql及设置远程访问方法

    ubuntu上安装mysql非常简单只需要几条命令就可以完成. 1. sudo apt-get install mysql-server   2. apt-get isntall mysql-clie ...

  2. Redis具体解释与常见问题解决方式

    Redis简单介绍 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对很多其它.包含string(字符串).list(链表).set(集合).zset ...

  3. Scala集合类详解

    对scala中的集合类虽然有使用,但是一直处于一知半解的状态.尤其是与java中各种集合类的混合使用,虽然用过很多次,但是一直也没有做比较深入的了解与分析.正好趁着最近项目的需要,加上稍微有点时间,特 ...

  4. ElasticSearch排序Java api简单Demo

    代码: String time1 = ConstValue.GetCurrentDate(); SortBuilder sortBuilder = SortBuilders.fieldSort(&qu ...

  5. PAT Maximum Subsequence Sum[最大子序列和,简单dp]

    1007 Maximum Subsequence Sum (25)(25 分) Given a sequence of K integers { N~1~, N~2~, ..., N~K~ }. A ...

  6. 如何给Pycharm加上头行 # *_*coding:utf-8 *_*?

    File>Setting>Editor>Code Style>File and Code Templates>Python Script  后面加上 # *_*codin ...

  7. zw版【转发·台湾nvp系列Delphi例程】HALCON SetComprise1

    zw版[转发·台湾nvp系列Delphi例程]HALCON SetComprise1 procedure TForm1.Button1Click(Sender: TObject);var image0 ...

  8. 填格子3*N的方框使用2*1的矩形进行填充

    考虑每个位置的前一个状态 可以发现有 我们分别给他们编号 假设 现在填充到了i+1行,我们可以发现从i行可以通过填充转到i+1行的状态 第i行第j列表示 可以 从上一个转态 j 可以到达这个状态的j ...

  9. uva10003

    /* 2014.3.6 这题说的是给你了一根木棒 然后 n 个点(线段上的点) 然后计算 在这 n个点上都切下去的 最小花费 举个例子 100 3 25 50 75 如果 从 25 开始切 然后切 5 ...

  10. 通过canal实现把MySQL数据实时增量到kafka

    说明:我们有一个业务需要把mysql中一些表实时同步到大数据集群hbase上面,我们先通过sqoop把表中数据全量导入到hbase中,然后再通过canal定位的某个binlog的position,来实 ...