003 接触elasticsearch的Restful Api

  在学习的时候,直接参看网上的材料,总是会有各种问题,也可能是版本的问题的差异,也可能是本来就有问题,所以,学习了很久后,决定从官网的文档上进行学习。

  其中7.2版本的文档是:https://www.elastic.co/guide/en/elasticsearch/reference/7.2/docs.html

一:前置小学习

1.集群健康

  GET /_cat/health?v

  效果:

  

  my-application集群的状态位yellow。

2.节点列表

  

3.查看全部的索引

  GET /_cat/indices?v

  

4.新建索引

  新建一个customer的索引,然后查看索引。

  其中,pretty的意思是响应以Json格式返回。

  

  再查看所有的索引:

  

  关于customer索引,有1个主分片,1个副本,0个文档。

  健康状态是yellow,因为副本没有被分配,在默认情况下为这个索引创建了一个副本,但是只有一个节点在运行,所以,只有再有一个节点被加入到集群中才会分配一个副本,一旦副本被分配到第二个节点上,索引的状态才会变成green。

  关于集群,将会再后期进行部署,测试。

二:文档学习

1.新建索引

  索引API在特定索引中添加或更新JSON文档,使其可搜索。下面的示例将JSON文档插入到ID为1的“twitter”索引中:

1 PUT twitter/_doc/1
2 {
3     "user" : "kimchy",
4     "post_date" : "2009-11-15T14:12:12",
5     "message" : "trying out Elasticsearch"
6 }

  截图:

  

  说明:

  The _shards header provides information about the replication process of the index operation:

  _shards头提供有关索引操作的复制过程的信息

  total
  Indicates how many shard copies (primary and replica shards) the index operation should be executed on.
  主与副本分片,需要执行的总个数。
  successful
  Indicates the number of shard copies the index operation succeeded on.
  failed
  An array that contains replication-related errors in the case an index operation failed on a replica shard.

猜你喜欢

转载自www.cnblogs.com/juncaoit/p/11248394.html
003