elasticsearch的rest访问格式:
  1. curl -X<REST Verb> <Node>:<Port>/<Index>/<Type>/<ID>

1、启动

  1. [es@vm1 bin]$ ./elasticsearch --cluster.name myes --node.name node1

2、查看集群状态
  1. [es@vm1 ~]$ curl http://vm1:9200/_cat/health?v
  2. epoch      timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks
  3. 1432704777 22:32:57  myes    green

3、查看节点列表
  1. [es@vm1 ~]$ curl http://vm1:9200/_cat/nodes?v
  2. host ip             heap.percent ram.percent load node.role master name  
  3. vm1  192.168.1.111     3           24 0.04 d         *       node1

4、查看index列表
  1. [es@vm1 ~]$ curl http://vm1:9200/_cat/indices?v
  2. health status index pri rep docs.count docs.deleted store.size pri.store.size

5、创建index
  1. [es@vm1 ~]$ curl -XPUT http://vm1:9200/customer?pretty   
  2. {
  3.   "acknowledged" : true
  4. }

6、添加一个document
  1. [es@vm1 ~]$ curl -XPUT vm1:9200/customer/external/1?pretty -d '{"name":"lisg"}'
  2. {
  3.   "_index" : "customer",
  4.   "_type" : "external",
  5.   "_id" : "1",
  6.   "_version" : 4,
  7.   "created" : true
  8. }

7、检索一个document
  1. [es@vm1 ~]$ curl -XGET vm1:9200/customer/external/1?pretty
  2. {
  3.   "_index" : "customer",
  4.   "_type" : "external",
  5.   "_id" : "1",
  6.   "_version" : 4,
  7.   "found" : true,
  8.   "_source":{"name":"lisg"}
  9. }

8、删除一个document
  1. [es@vm1 ~]$ curl -XDELETE vm1:9200/customer/external/1?pretty
  2. {
  3.   "found" : true,
  4.   "_index" : "customer",
  5.   "_type" : "external",
  6.   "_id" : "1",
  7.   "_version" : 5
  8. }

9、删除一个type
  1. [es@vm1 ~]$ curl -XDELETE vm1:9200/customer/external?pretty
  2. {
  3.   "acknowledged" : true
  4. }

10、删除一个index
  1. [es@vm1 ~]$ curl -XDELETE vm1:9200/customer?pretty
  2. {
  3.   "acknowledged" : true
  4. }

11、POST方式可以添加一个document,不用指定ID
  1. [es@vm1 ~]$ curl -XPOST vm1:9200/customer/external?pretty -d '{"name":"zhangsan"}'
  2. {
  3.   "_index" : "customer",
  4.   "_type" : "external",
  5.   "_id" : "AU2UAazzBzlrcKeIwh7T",
  6.   "_version" : 1,
  7.   "created" : true
  8. }

12、使用doc更新document
[es@vm1 ~]$ curl -XPUT vm1:9200/customer/external/1?pretty -d '{"name":"lisg4", "age":28}'
{
  "_index" : "customer",
  "_type" : "external",
  "_id" : "1",
  "_version" : 4,
  "created" : false
}
13、使用script更新document(1.4.3版本动态脚本是被禁止的)
[es@vm1 ~]$ curl -XPOST vm1:9200/customer/external/1/_update?pretty -d '{"script":"ctx._source.age += 5"}'
{
  "error" : "ElasticsearchIllegalArgumentException[failed to execute script]; nested: ScriptException[dynamic scripting for [groovy] disabled]; ",
  "status" : 400
}
14、查询全部
[es@vm1 ~]$ curl -XGET vm1:9200/customer/external/_search?pretty
{
  "took" : 12,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "customer",
      "_type" : "external",
      "_id" : "AU2UAazzBzlrcKeIwh7T",
      "_score" : 1.0,
      "_source":{"name":"zhangsan"}
    }, {
      "_index" : "customer",
      "_type" : "external",
      "_id" : "1",
      "_score" : 1.0,
      "_source":{"name":"lisg4", "age":28}
    }, {
      "_index" : "customer",
      "_type" : "external",
      "_id" : "2",
      "_score" : 1.0,
      "_source":{"name":"dengsl"}
    } ]
  }
}
15、批量操作,{}之间要换行
  1. [es@vm1 ~]$ curl -XPOST vm1:9200/customer/external/_bulk?pretty -d '
  2. > {index:{_id:3}}
  3. > {name:"zhangsan", age:28}
  4. > {index:{_id:4}}
  5. > {name:"lisi", age:29}
  6. > {update:{_id:4}}
  7. > {doc:{name:"lisi2", age:30}}
  8. > {delete:{_id:"AU2UAazzBzlrcKeIwh7T"}}
  9. > '
  10. {
  11.   "took" : 34,
  12.   "errors" : false,
  13.   "items" : [ {
  14.     "index" : {
  15.       "_index" : "customer",
  16.       "_type" : "external",
  17.       "_id" : "3",
  18.       "_version" : 1,
  19.       "status" : 201
  20.     }
  21.   }, {
  22.     "index" : {
  23.       "_index" : "customer",
  24.       "_type" : "external",
  25.       "_id" : "4",
  26.       "_version" : 1,
  27.       "status" : 201
  28.     }
  29.   }, {
  30.     "update" : {
  31.       "_index" : "customer",
  32.       "_type" : "external",
  33.       "_id" : "4",
  34.       "_version" : 2,
  35.       "status" : 200
  36.     }
  37.   }, {
  38.     "delete" : {
  39.       "_index" : "customer",
  40.       "_type" : "external",
  41.       "_id" : "AU2UAazzBzlrcKeIwh7T",
  42.       "_version" : 2,
  43.       "status" : 200,
  44.       "found" : true
  45.     }
  46.   } ]
  47. }

上面的语句顺序执行的操作有:
1)添加索引:张三,28
2)添加索引:李四,29
3)更新李四:李四2,30
4)删除索引:id是AU2UAazzBzlrcKeIwh7T的索引

16、从文件中加载数据(accounts.json见附件)
  1. [es@vm1 ~]$ curl -XPOST http://vm1:9200/customer/external/_bulk?pretty --data-binary @accounts.json 
  2. [es@vm1 ~]$ curl -XGET vm1:9200/_cat/indices?v
  3. health status index    pri rep docs.count docs.deleted store.size pri.store.size 
  4. yellow open   customer   5   1       1000            0    442.3kb        442.3kb 

17、















附件列表

elasticsearch常用命令的更多相关文章

  1. elasticsearch 常用命令

    #查看集群状态 curl -XGET "http://localhost:9200/_cluster/health?pretty" #查看所有的快照 curl -XGET &quo ...

  2. 实战ELK(2) ElasticSearch 常用命令

    1.Cluster Health 集群状态 curl 'localhost:9200/_cat/health?v' yellow代表分片副本确实,因为我们现在只有一台机器. curl 'localho ...

  3. elasticsearch 常用命令(一)

    索引 搜索 mapping 分词器 1.创建索引 http://192.168.65.131:9200/smartom_index?pretty 2.查看索引: http://192.168.65.1 ...

  4. elasticsearch 常用命令 一直红色 重启不稳定 不停的宕机

    persistent (重启后设置也会存在) or transient (整个集群重启后会消失的设置). 查看集群状态和每个indices状态.搜索到red的,没用就删除 GET /_cluster/ ...

  5. ElasticSearch——常用命令

    集群相关 --查询集群健康状态 GET _cluster/health --查询所有节点 GET _cat/nodes --查询索引及分片的分布 GET _cat/shards --查询指定索引分片的 ...

  6. elasticsearch常用命令备注

    1.检查集群健康状态 curl 'localhost:9200/_cat/health?v' 2.检查节点健康状态 curl 'localhost:9200/_cat/nodes?v' 3.新增一条索 ...

  7. elasticsearch(四) 之 elasticsearch常用的一些集群命令

    目录 elasticsearch常用的一些集群命令 查看集群健康状态 查看集群的节点列表 查看所有的索引 删除索引 查询索引的某个文档内容 更新文档 删除文档 自动创建索引 定时删除索引 elasti ...

  8. elasticsearch 索引清理脚本及常用命令

    elastic索引日志清理不及时,很容易产生磁盘紧张,官网给出curl -k -XDELETE可以清理不需要的索引日志. 清理脚本 #!/bin/bash #Author: 648403020@qq. ...

  9. Docker安装和常用命令

    Docker安装 Docker的安装可以参考 https://docs.docker.com/ 下面的 Get Docker / Docker CE / Linux, 需要关注的主要是CentOS和U ...

随机推荐

  1. FFmpeg 结构体学习(五): AVCodec 分析

    在上文FFmpeg 结构体学习(四): AVFrame 分析我们学习了AVFrame结构体的相关内容.本文,我们将讲述一下AVCodec. AVCodec是存储编解码器信息的结构体.下面我们来分析一下 ...

  2. java前后分离使用fetch上传文件失败500

    这次不是写什么技术要点,仅仅是记录一下 最近遇到的一个问题 背景 使用fetch向java后台上传文件时,前端调试报错500,后端的报错为multipart 无法解析,翻译过来大概是这个意思. 由于本 ...

  3. [Swift]LeetCode632. 最小区间 | Smallest Range

    You have k lists of sorted integers in ascending order. Find the smallest range that includes at lea ...

  4. linux入门--Linux发行版本详解

    从技术上来说,李纳斯•托瓦兹开发的 Linux 只是一个内核.内核指的是一个提供设备驱动.文件系统.进程管理.网络通信等功能的系统软件,内核并不是一套完整的操作系统,它只是操作系统的核心.一些组织或厂 ...

  5. PHP算法之冒泡排序

    //冒泡排序 //①思路,先比较出第一次,找一个最大的值,排到最后; //②重复count遍之后,就能得到排序; //③优化,每一次循环之后不需要再次全部重复; $array = [11,5,4,58 ...

  6. Spring多线程批量发送邮件(ThreadPoolTaskExecutor)

    1,需求:使用多线程批量发送邮件 需要批量发送邮件大概400封左右,但是因为发送邮件受网络限制,所以经常导致等待超时.所以就想到了使用多线程来发邮件,因为是异步的所以返回结果不受发邮件影响. 2,思路 ...

  7. Python Matplotlib.pyplot plt 中文显示

    话不多说,上代码 # -*- coding: UTF-8 -*- import matplotlib.pyplot as plt from matplotlib.font_manager import ...

  8. 微信小程序代码构成

    一.小程序代码 app.json 是当前小程序的全局配置,包括了小程序的所有页面路径.界面表现.网络超时时间.底部tab等. { "pages":[ "pages/ind ...

  9. C#版(打败99.28%的提交) - Leetcode 347. Top K Frequent Elements - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

  10. java 取汉字首字母

    有时候,可能会有一些类似这样的需求: 对于这样的效果,我们可以有类似这样的解决方案: package bys.utils; import java.io.UnsupportedEncodingExce ...