kibana Dev Tools--增删改查语句

创建索引、修改/新增数据、查询数据、删除索引的基本方法

kibana Dev Tools增删改查基础知识:https://www.cnblogs.com/bigfacecat-h/p/14490917.html
kibana Dev Tools查询示例:https://www.cnblogs.com/bigfacecat-h/p/elasticSearch.html
kibana Dev Tools修改示例:https://www.cnblogs.com/bigfacecat-h/p/14498221.html
kibana Dev Tools常用命令:https://www.cnblogs.com/bigfacecat-h/p/14500466.html

先看下图,在kibana devTool中写的一个查询语句 :

GET  alxxx.manual.call.history.topic/logs/_search

上图中:

alxxx.manual.call.history.topic  --表示index  索引 

logs  --表示type

_search  --表示执行查询操作

_id  --表示文档id

在ES中,有的版本支持一个index下可以有多个type,但7版本之后,ES不再支持一个index可以创建多个type,即一个index下只能有一个type,且type名字都默认为_doc

即在7版本之后,以上的查询语句就是: GET  alxxx.manual.call.history.topic/_doc/_search

其他字段说明:

创建索引、更新数据可以使用POT或 PUT,但两者有区别:

1、创建索引时,POST命令不需要指定文档id(可以指定也可以不指定),PUT必须指定文档id

2、更新数据时,PUT会将新的json值完全替换掉旧的;而POST方式只会更新相同字段的值,其他数据不会改变,新提交的字段若不存在则增加

3、PUT是幂等等操作,即将A修改为B,第一次请或多次的结果都是一样的,查询会发现结果中始终只有一条B的记录

      POST不是幂等操作,若要将A修改为B,则每次请求都会新增一份数据,如果请求5次,就会生成5分数据(文档id不同),查询会发现结果中有5条B的记录

1、PUT创建索引(必须指定文档id)

PUT /index_bigfacecat_test/typeA/1
{
  "name": "big face cat",
  "age": 18
}

 2、POST创建索引(不指定文档id)

POST /index_littefacecat_test/typeA
{
  "name": "litte face cat",
  "age": 18
}

 2、查询数据( 查询语句用法见《https://www.cnblogs.com/bigfacecat-h/p/elasticSearch.html》)

GET /index_bigfacecat_test/typeA/_search
{
  "query": {
    "match_all": {}
  }
}

 

GET /index_littefacecat_test/typeA/_search
{
  "query": {
    "match_all": {}
  }
}

3、PUT修改数据:直接将原有数据全部替换掉

PUT /index_bigfacecat_test/typeA/1
{
   "name": "大脸猫",
   "age": 99,
   "address":"重庆"
}

 4、POST不指定文档id时:是在同样的索引下新增了一条数据,而不是在原有数据的基础上修改

6、POST指定了文档id时,则只修改对应文档id中的数据,不会新增一份资源,且仅更新相同字段的值,其他数据不会改变,若新提交的字若不存在则增加该字段

POST /index_bigfacecat_test/typeA/1
{
    "name": "大脸猫2 ",
    "age": 999,
    "addree":"重庆2",
    "sex":"female"
}

 7、当只修改某几个字段的值时,只能用POS修改,因为PUT会用请求中的数据全部替换掉库中的整条记录

POST /index_bigfacecat_test/typeA/1/_update
{
   "doc":{
      "name": "大脸猫3",
      "age":1000,
      "hobby":"露营"
   }
 
}

  

7、批量创建

POST /index_bigfacecat_test/typeA/_bulk
{"index":{"_id":"5"}}
{"name": "大脸猫5" }
{"index":{"_id":"6"}}
{"name": "大脸猫66" }

8、批量更新或删除  

POST /index_bigfacecat_test/typeA/_bulk
{"update":{"_id":"5"}}
{"doc": { "name": "big face cat 5" } }
{"update":{"_id":"5"}}
{"doc": { "sex": "female" }}
{"delete":{"_id":"6"}}
{"delete":{"_id":"1"}}

  

7、删除数据

删除指定文档id的数据: DELETE /index_littefacecat_test/typeA/AXgGn-gEICegWRWVwWZQ

删除指定索引下的所有数据:DELETE /index_littefacecat_test/

8、查看所有index的语句

GET /_cat/indices?format=json

9、查询指定 Index 的 mapping

GET /index_bigfacecat_test/_mapping

原文地址:https://www.cnblogs.com/bigfacecat-h/p/14490917.html