一.创建索引

PUT twitter

{

"settings" : {

"index" : {

"number_of_shards" : 3,

"number_of_replicas" : 2

}

}

}

语法规则:https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html

备注:

1.number_of_shards:索引分片数

2.number_of_replicas:索引副本数

3.index可以简写

具体索引字段见:https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html

二.获取索引

1.GET /twitter

{

"twitter": {

"aliases": {},

"mappings": {},

"settings": {

"index": {

"creation_date": "1505635897531",

"number_of_shards": "3",

"number_of_replicas": "2",

"uuid": "VpozplmDTIObzv-lUXryuw",

"version": {

"created": "5060099"

},

"provided_name": "twitter"

}

}

}

}

2.GET twitter/[_settings|_mappings|_aliases] - 分别获取与之对应的内容节点信息

三.删除索引

DELETE /twitter

四.关闭和开启索引

1.关闭索引

POST /twitter/_close

2.开启索引

POST /twitter/_open

五.创建索引类型

PUT twitter

{

"mappings": {

"tweet": {

"properties": {

"message": {

"type": "text"

}

}

}

}

}

注:如果索引不存在则创建,已存在则会报错.如下:

{

"error": {

"root_cause": [

{

"type": "index_already_exists_exception",

"reason": "index [twitter/Exa9xht9SUe_djnaOhX4fA] already exists",

"index_uuid": "Exa9xht9SUe_djnaOhX4fA",

"index": "twitter"

}

],

"type": "index_already_exists_exception",

"reason": "index [twitter/Exa9xht9SUe_djnaOhX4fA] already exists",

"index_uuid": "Exa9xht9SUe_djnaOhX4fA",

"index": "twitter"

},

"status": 400

}

那么如果针对已存在的索引增加一个类型?

PUT twitter/_mapping/user

{

"properties": {

"name": {

"type": "text"

}

}

}

批量给多个索引增加一个操作类型

PUT aa,bb,cc/_mapping/test

{

"properties": {

"name": {

"type": "text"

}

}

}

文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html

六.获取索引类型

1.获取某个索引下单个类型

GET /twitter/_mapping/game

2.全局匹配某个类型

GET /_mapping/game

3.获取全部类型

GET /_all/_mapping

GET /_mapping

七.添加数据

PUT twitter/tweet/1

{

"user" : "kimchy",

"post_date" : "2009-11-15T14:12:12",

"message" : "trying out Elasticsearch"

}

注:

1.不存则添加否则更新.

2.索引/类型/主键ID

3.twitter/tweet/1?op_type=create只负责创建,存在则报错

8.乐观锁

PUT twitter/tweet/1?version=2

{

"message" : "elasticsearch now has versioning support, double cool!"

}

9.主键ID自增

POST twitter/tweet/

{

"user" : "kimchy",

"post_date" : "2009-11-15T14:12:12",

"message" : "trying out Elasticsearch"

}

主键ID生成格式:AV6PKkAT4fkb07FW6KlE

10.获取数据

1.正常返回数据格式

GET twitter/tweet/0

返回:

{

"_index": "twitter",

"_type": "tweet",

"_id": "1",

"_version": 4,

"found": true,

"_source": {

"user": "kimchy",

"post_date": "2009-11-15T14:12:12",

"message": "trying out Elasticsearch"

}

}

2.获取source原数据

GET /twitter/tweet/1/_source

{

"_index": "twitter",

"_type": "tweet",

"_id": "1_source=false",

"found": false

}

文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html

11.修改数据

POST twitter/tweet/1/_update

{

"script" : {

"source": "ctx._source.user += params.user",

"lang": "painless",

"params" : {

"user" : "blue"

}

}

}

注:更新tweet类型中user字段,拼接更新.最终结果:??????blue

合并更新

POST test/type1/1/_update

{

"doc" : {

"user" : "new_name"

}

}

文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html

12.删除数据

DELETE /twitter/tweet/1

结语

推荐使用一款软件:postman

转载于:https://www.cnblogs.com/huizong/p/7536606.html

elasticsearch restful api操作使用指南相关推荐

  1. asp编程工具_使用ASP.NET Core构建RESTful API的技术指南

    译者荐语:利用周末的时间,本人拜读了长沙.NET技术社区翻译的技术文章<微软RESTFul API指南>,打算按照步骤写一个完整的教程,后来无意中看到了这篇文章,与我要写的主题有不少相似之 ...

  2. 使用ASP.NET Core构建RESTful API的技术指南

    译者荐语:利用周末的时间,本人拜读了长沙.NET技术社区翻译的技术文章<微软RESTFul API指南>,打算按照步骤写一个完整的教程,后来无意中看到了这篇文章,与我要写的主题有不少相似之 ...

  3. php restful规范,RESTFul API规范 详细指南

    RESTFul规范 RESTFul是一种HTTP API接口规范,只要满足的RESTFul规范,即可称为RESTFul API. 既然是接口,我们先来了解一下,他和传统的API接口有何不同吧. 本文以 ...

  4. 通过HTTP RESTful API 操作elasticsearch搜索数据

    样例数据集 这是编造的JSON格式银行客户账号信息文档,文档schema如下: { "account_number": 0, "balance": 16623, ...

  5. elasticsearch rest api操作

    REST(REpresentational State Transfer)从字面看就是"表述性状态传输",它通常是开发的一种约定,当所有的开发者都遵从这种约定的时候,可以大大简化开 ...

  6. Elasticsearch java api操作(一)(Java Low Level Rest Client)

    一.说明: 一.Elasticsearch提供了两个JAVA REST Client版本: 1.java low level rest client: 低级别的rest客户端,通过http与集群交互, ...

  7. Elasticsearch Restful API

    http://192.168.10.16:9200/<index>/<type>/[<id>] index可以理解为数据库:type理解为数据表:id相当于数据库表 ...

  8. 【转载】Elasticsearch客户端API使用Demo

    Elasticsearch客户端API使用Demo, 转载自官方文档, 以索引雇员文档为示例, 在命令行使用curl演示了一系列的Restful API操作. 1.索引雇员文档 第一个业务需求就是存储 ...

  9. Elasticsearch入常用RESTful API总结

    RESTful API HTTP动词介绍 对于资源的具体操作类型,由HTTP动词表示. 常用的HTTP动词有下面五个(括号里是对应的SQL命令). GET(SELECT):从服务器取出资源(一项或多项 ...

最新文章

  1. css海浪动画代码,不行一行代码,纯css实现海浪动态效果!
  2. springboot集成freemarker 配置application.properties详解
  3. Spring Cloud Alibaba基础教程:Nacos的数据持久化
  4. UA MATH567 高维统计I 概率不等式10 Bernstein不等式
  5. 多变量线性回归 原理
  6. [十三]JavaIO之PushBackInputStream
  7. c语言表白代码颜色,C语言告白代码,一闪一闪亮晶晶~
  8. 机器学习实战(十)Apriori(关联分析)
  9. 网站页面底端“本站已经安全运行XX年XX天XX秒“代码
  10. 微信小程序地图实现多个位置标记marker
  11. YAML和JSON对比
  12. word批量修改图片的大小
  13. 阿里云网站域名备案流程全过程(图文讲解)
  14. android 2d 漫画界面,宅男舔屏必备!动漫人物Live2d壁纸App
  15. 计算机信息量单位kbit,网络的带宽和速率
  16. php里pluck,Pluck CMS后台另两处任意代码执行
  17. linux服务器怎么查看cpu配置信息,linux服务器cpu信息查看详解
  18. [SpringCould篇]之服务消费方式Ribbon+RestTemplate
  19. 宏碁暗影骑士AN515-55/57/58原厂预装系统oem镜像
  20. c/c++算法之“24点”经典问题

热门文章

  1. 苹果将在内华达州里诺市再购地块 都是为了它
  2. Linux学习笔记:rpm程序包管理
  3. openSUSE 11.2 文泉中文字体安装
  4. 1:1 人脸比对 开源_打破5个神话:在高等教育中使用开源
  5. 一台微型计算机_Linux的上百万行代码,一台新的微型计算机以及Google和Microsoft的更多产品
  6. Dave和Gunnar采访Lauren Egts:Raspberry Pi,Scratch等
  7. HTML5 Canvas的基本用法
  8. Bootstrap 标签页Tab插件的事件
  9. CSS两栏布局之右栏布局
  10. es6 ArrayBuffer对象