论坛首页 综合技术论坛

elasticsearch常用操作示例

浏览 1659 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2018-03-04  

1. 创建库

PUT http://localhost:9200/secisland?pretty/ 

建库成功则返回:

{

  "acknowledged": true

}

 

2. 查询库的状态

http://localhost:9200/_cat/indices?v

或者在Head插件里概览页签中查看库的状态

 

3. 插入数据

请求:PUT http://localhost:9200/secisland/secilog/1/

参数:

{

  "computer":"secisland",

  "message":"secisland is an security company!"

}

返回值:

{

  "_index": "secisland",

  "_type": "secilog",

  "_id": "1",

  "_version": 1,

  "_shards": {

    "total": 2,

    "successful": 1,

    "failed": 0

  },

  "created": true

}

 

4. 修改文档

请求:POST http://localhost:9200/secisland/secilog/1/_update

参数:

{

  "doc":{

    "computer":"secisland",

    "message":"secisland is an security company! It provides log analysis products!"

  }

}

返回值:

{

  "_index": "secisland",

  "_type": "secilog",

  "_id": "1",

  "_version": 2,

  "_shards": {

    "total": 2,

    "successful": 1,

    "failed": 0

  }

}

 

5. 查询文档

请求:GET http://localhost:9200/secisland/secilog/1/

返回值:

{

  "_index": "secisland",

  "_type": "secilog",

  "_id": "1",

  "_version": 2,

  "found": true,

  "_source": {

    "computer": "secisland",

    "message": "secisland is an security company! It provides log analysis products!"

  }

}

 

6. 删除文档

请求:DELETE http://localhost:9200/secisland/secilog/1/

返回值:

{

  "found": true,

  "_index": "secisland",

  "_type": "secilog",

  "_id": "1",

  "_version": 3,

  "_shards": {

    "total": 2,

    "successful": 1,

    "failed": 0

  }

}

 

7. 删除库

请求: DELETE http://localhost:9200/secisland/

返回值:

{

  "acknowledged": true

}

 

论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics