使用curl命令操作elasticsearch

大岩不灿 发表于 2015年4月25日 浏览 13,463 次

第一:_cat系列
_cat系列提供了一系列查询elasticsearch集群状态的接口。你可以通过执行
curl -XGET localhost:9200/_cat
获取所有_cat系列的操作
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
你也可以后面加一个v,让输出内容表格显示表头,举例

name       component        version type url
Prometheus analysis-mmseg NA j
Prometheus analysis-pinyin NA j
Prometheus analysis-ik NA j
Prometheus analysis-ik NA j
Prometheus analysis-smartcn 2.1.0 j
Prometheus segmentspy NA s /_plugin/segmentspy/
Prometheus head NA s /_plugin/head/
Prometheus bigdesk NA s /_plugin/bigdesk/
Xandu analysis-ik NA j
Xandu analysis-pinyin NA j
Xandu analysis-mmseg NA j
Xandu analysis-smartcn 2.1.0 j
Xandu head NA s /_plugin/head/
Xandu bigdesk NA s /_plugin/bigdesk/
Onyxx analysis-ik NA j
Onyxx analysis-mmseg NA j
Onyxx analysis-smartcn 2.1.0 j
Onyxx analysis-pinyin NA j
Onyxx head NA s /_plugin/head/
Onyxx bigdesk NA s /_plugin/bigdesk/

第二:_cluster系列
1、查询设置集群状态
curl -XGET localhost:9200/_cluster/health?pretty=true
pretty=true表示格式化输出
level=indices 表示显示索引状态
level=shards 表示显示分片信息
2、curl -XGET localhost:9200/_cluster/stats?pretty=true
显示集群系统信息,包括CPU JVM等等
3、curl -XGET localhost:9200/_cluster/state?pretty=true
集群的详细信息。包括节点、分片等。
3、curl -XGET localhost:9200/_cluster/pending_tasks?pretty=true
获取集群堆积的任务
3、修改集群配置
举例:

curl -XPUT localhost:9200/_cluster/settings -d '{
"persistent" : {
"discovery.zen.minimum_master_nodes" : 2
}
}'

transient 表示临时的,persistent表示永久的
4、curl -XPOST ‘localhost:9200/_cluster/reroute’ -d ‘xxxxxx’
对shard的手动控制,参考http://zhaoyanblog.com/archives/687.html
5、关闭节点
关闭指定192.168.1.1节点
curl -XPOST ‘http://192.168.1.1:9200/_cluster/nodes/_local/_shutdown’
curl -XPOST ‘http://localhost:9200/_cluster/nodes/192.168.1.1/_shutdown’
关闭主节点
curl -XPOST ‘http://localhost:9200/_cluster/nodes/_master/_shutdown’
关闭整个集群
$ curl -XPOST ‘http://localhost:9200/_shutdown?delay=10s’
$ curl -XPOST ‘http://localhost:9200/_cluster/nodes/_shutdown’
$ curl -XPOST ‘http://localhost:9200/_cluster/nodes/_all/_shutdown’
delay=10s表示延迟10秒关闭

第三:_nodes系列
1、查询节点的状态
curl -XGET ‘http://localhost:9200/_nodes/stats?pretty=true’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2/stats?pretty=true’
curl -XGET ‘http://localhost:9200/_nodes/process’
curl -XGET ‘http://localhost:9200/_nodes/_all/process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/jvm,process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/info/jvm,process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/_all
curl -XGET ‘http://localhost:9200/_nodes/hot_threads

第四:索引操作

1、获取索引
curl -XGET ‘http://localhost:9200/{index}/{type}/{id}’
2、索引数据
curl -XPOST ‘http://localhost:9200/{index}/{type}/{id}’ -d'{“a”:”avalue”,”b”:”bvalue”}’
3、删除索引
curl -XDELETE ‘http://localhost:9200/{index}/{type}/{id}’
4、设置mapping

curl -XPUT http://localhost:9200/{index}/{type}/_mapping -d '{
"{type}" : {
"properties" : {
"date" : {
"type" : "long"
},
"name" : {
"type" : "string",
"index" : "not_analyzed"
},
"status" : {
"type" : "integer"
},
"type" : {
"type" : "integer"
}
}
}
}'

5、获取mapping
curl -XGET http://localhost:9200/{index}/{type}/_mapping
6、搜索

curl -XGET 'http://localhost:9200/{index}/{type}/_search' -d '{
"query" : {
"term" : { "user" : "kimchy" } //查所有 "match_all": {}
},
"sort" : [{ "age" : {"order" : "asc"}},{ "name" : "desc" } ],
"from":0,
"size":100
}
curl -XGET 'http://localhost:9200/{index}/{type}/_search' -d '{
"filter": {"and":{"filters":[{"term":{"age":"123"}},{"term":{"name":"张三"}}]},
"sort" : [{ "age" : {"order" : "asc"}},{ "name" : "desc" } ],
"from":0,
"size":100
}

ElasticSearch 基础<转载>的更多相关文章

  1. ELK(elasticsearch+kibana+logstash)搜索引擎(二): elasticsearch基础教程

    1.elasticsearch的结构 首先elasticsearch目前的结构为 /index/type/id  id对应的就是存储的文档ID,elasticsearch一般将数据以JSON格式存储. ...

  2. Elasticsearch 基础入门

    原文地址:Elasticsearch 基础入门 博客地址:http://www.extlight.com 一.什么是 ElasticSearch ElasticSearch是一个基于 Lucene 的 ...

  3. ElasticSearch 基础 1

    ElasticSearch 基础=============================== 索引创建 ========================== 1. RESTFUL APIAPI 基本 ...

  4. Elasticsearch基础但非常有用的功能之二:模板

    文章转载自: https://mp.weixin.qq.com/s?__biz=MzI2NDY1MTA3OQ==&mid=2247484584&idx=1&sn=accfb65 ...

  5. 最完整的Elasticsearch 基础教程

    翻译:潘飞(tinylambda@gmail.com) 基础概念 Elasticsearch有几个核心概念.从一开始理解这些概念会对整个学习过程有莫大的帮助. 接近实时(NRT)        Ela ...

  6. ELK 之一:ElasticSearch 基础和集群搭建

    一:需求及基础: 场景: 1.开发人员不能登录线上服务器查看详细日志 2.各个系统都有日志,日志数据分散难以查找 3.日志数据量大,查询速度慢,或者数据不够实时 4.一个调用会涉及到多个系统,难以在这 ...

  7. Elasticsearch基础教程

    Reference: http://blog.csdn.net/cnweike/article/details/33736429 基础概念 Elasticsearch有几个核心概念.从一开始理解这些概 ...

  8. elasticsearch基础概念

    接近实时(NRT)        Elasticsearch是一个接近实时的搜索平台.这意味着,从索引一个文档直到这个文档能够被搜索到有一个轻微的延迟(通常是1秒).           集群(clu ...

  9. Elasticsearch基础知识分享

    1. Elasticsearch背景介绍 Elasticsearch 是一个基于 Lucene 的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于 RESTful web 接口.Elast ...

  10. Elasticsearch基础教程分享

    基础及相关资料 首先我们先了解一下什么是Elastisearch,Elasticsearch(简称es)是一个基于Lucene库的搜索引擎.它提供了一个分布式.支持多租户的全文搜索引擎,具有HTTP  ...

随机推荐

  1. _编程语言_C++_setw()

    C++ 中使用setw(int n) 来控制输出间隔. 例如: cout<<)<<'a'<<endl;//s与a之间有7个空格,setw()只对后面紧跟的输出产生作 ...

  2. 移动端 - Android客户端性能测试常见指标

    rom版本的性能测试 一般关注功耗(不过 rom 版本的功耗测试跟应用的功耗测试会有所差异,当然只是用例设计方面的差异,工具仍然采用安捷伦电源仪进行) 应用的性能测试 包括很多测试项,如启动时间.内存 ...

  3. mysql 中 datetime和 timestamp的区别

    DATETIME日期和时间的组合.支持的范围是'1000-01-01 00:00:00'到'9999-12-31 23:59:59'.MySQL以'YYYY-MM-DD HH:MM:SS'格式显示DA ...

  4. OpenGL中的拾取模式( Picking)

    1. Opengl中的渲染模式有三种:(1)渲染模式,默认的模式:(2)选择模式, (3)反馈模式.如下 GLint glRenderMode(GLenum mode) mode可以选取以下三种模式之 ...

  5. 《mysql必知必会》学习_sql文件导入数据库_20180724_欢

    解决问题1:MySQL中导入sql文件. 步骤1:show databases;#看看我有什么数据库 步骤2:use hh;#我要用hh这个数据库,返回database changed说明打开成功. ...

  6. hdu 2642

    这题应该就是标准的二维树状数组,应该没什么难度 处理一下x,y等于0的情况就过了 #include <iostream> #include <cstdio> #include ...

  7. [正则表达式] PHP 中使用正则表达式收集(2016/01/08 - )

    // 1. 过滤字符串中src 属性为空的img 标签 $filterBack = preg_replace("/<img[^<>]*src\=[\'\"][\' ...

  8. C - Roll-call in Woop Woop High

    Description The new principal of Woop Woop High is not satisfied with her pupils performance. She in ...

  9. 关于等效的物理意义 On the Physical Meaning of Equivalence

    当我们谈到两个物理概念是等效的,这意味着: 1.它们拥有同样的属性.例如质量和能量都可以弯曲空间. 2.它们可以在设计实验中无法区分彼此.例如恒星系统中行星的质量与恒星的引力. 3.它们可以互相转化. ...

  10. .Net桌面程序自动更新NAppUpdate

    自动更新介绍 我们做了程序,不免会有版本升级,这就需要程序有自动版本升级的功能.应用程序自动更新是由客户端应用程序自身负责从一个已知服务器下载并安装更新,用户唯一需要进行干预的是决定是否愿意现在或以后 ...