在咱们了解过 Elasticsearch 的概念,而且在咱们的机器上安装过 es 后, 咱们就能够简单操做一下。node
咱们前面提到 ES 是基于一个搜索库开发的,提供了大量 RESTful API 接口,所以咱们能够直接使用 curl 命令 或者 postman 这样的客户端去访问这些接口。docker
es 提供了一 套api,叫作 cat api,能够查看 es 中各类各样的数据json
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 1580201783 08:56:23 docker-cluster yellow 1 1 3 3 0 0 3 0 - 50.0%
上面查询出来的信息有不少,咱们暂时只关注 status 以及其对应的值: yellow。curl
status 对应了三个值,分别是 green,yellow,red,他们分别表明了集群的三种健康状态。post
每一个索引的primary shard和replica shard都是active状态的学习
每一个索引的primary shard都是active状态的,可是部分replica shard不是active状态,处于不可用的状态url
不是全部索引的 primary shard 都是 active 状态的,部分索引有数据丢失了code
查看索引索引
GET http://localhost:9200/_cat/indices?v
建立索引
PUT http://localhost:9200/test_index?pretty
删除索引
DELETE http://localhost:9200/test_index?pretty
模版: PUT /index/type/id
请求体:
{ "json数据" }
添加一条商品数据 PUT http://localhost:9200/ecommerce/product/1
请求体:
{ "name" : "黑人牙膏", "desc" : "薄荷味", "price" : 30 }
提示: es 会自动创建 index 和 type,不须要提早建立,并且 es 默认会对 document 每一个field都创建倒排索引(后面会介绍),让其能够被搜索
模版: GET /index/type/id
查询指定索引,类型,id 的商品信息 GET http://localhost:9200/ecommerce/product/1
修改商品信息 PUT http://localhost:9200/ecommerce/product/1
请求体:
{ "name" : "高露洁牙膏", "desc" : "清洁口气", "price" : 30 }
这种方式有一个缺点,必须带上全部的field,才能去进行信息的修改
修改商品信息 POST http://localhost:9200/ecommerce/product/1/_update
请求体:
{ "doc": { "name": "云南白药牙膏" } }
删除一个商品信息 DELETE http://localhost:9200/ecommerce/product/1
Elasticsearch 提供的检索功能很是复杂,这里介绍的是最基本的使用方法,后面会深刻讲解学习。