1 查看es中有哪些索引

GET /_cat/indices?v

es 中会默认存在一个名为.kibana的索引

表头的含义

health

green(集群完整) yellow(单点正常、集群不完整) red(单点不正常)

status

是否能使用

index

索引名

uuid

索引统一编号        

pri

主节点几个

rep

从节点几个

docs.count

文档数

docs.deleted

文档被删了多少

store.size

整体占空间大小

pri.store.size

主节点占

 

2 增加一个索引

PUT /movie_index

3 删除一个索引

ES 是不删除也不修改任何数据的,而是增加版本号

DELETE /movie_index

4. 新增文档

1)格式 PUT /index/type/id

PUT /movie_index/movie/1

{ "id":1,

  "name":"operation red sea",

  "doubanScore":8.5,

  "actorList":[ 

{"id":1,"name":"zhang yi"},

{"id":2,"name":"hai qing"},

{"id":3,"name":"zhang han yu"}

]

}

PUT /movie_index/movie/2

{

  "id":2,

  "name":"operation meigong river",

  "doubanScore":8.0,

  "actorList":[ 

{"id":3,"name":"zhang han yu"}

]

}

 

PUT /movie_index/movie/3

{

  "id":3,

  "name":"incident red sea",

  "doubanScore":5.0,

  "actorList":[ 

{"id":4,"name":"zhang chen"}

]

}

如果之前没建过index或者type,es 会自动创建。

5 直接用id查找

GET movie_index/movie/1

 

6 修改—整体替换

PUT /movie_index/movie/3

{

  "id":"3",

  "name":"incident red sea",

  "doubanScore":"5.0",

  "actorList":[ 

{"id":"1","name":"zhang chen"}

]

}

 

7 修改—某个字段

POST movie_index/movie/3/_update

{

  "doc": {

    "doubanScore":"7.0"

  }

}

 

8 删除一个document

DELETE movie_index/movie/3

 

9 搜索type全部数据

GET movie_index/movie/_search

结果

{

  "took": 2,    //耗费时间 毫秒

  "timed_out": false, //是否超时

  "_shards": {

    "total": 5,   //发送给全部5个分片

    "successful": 5,

    "skipped": 0,

    "failed": 0

  },

  "hits": {

    "total": 3,  //命中3条数据

    "max_score": 1,   //最大评分

    "hits": [  // 结果

      {

        "_index": "movie_index",

        "_type": "movie",

        "_id": 2,

        "_score": 1,

        "_source": {

          "id": "2",

          "name": "operation meigong river",

          "doubanScore": 8.0,

          "actorList": [

            {

              "id": "1",

              "name": "zhang han yu"

            }

          ]

        }

          。。。。。。。。

          。。。。。。。。

      }

 

10 按条件查询(全部)

GET movie_index/movie/_search

{

  "query":{

    "match_all": {}

  }

}

最后修改于 2021-06-16 15:56:43
上一篇