使用Elasticsearch不免要提到curl工具,curl是利用URL语法在命令行方式下工作的开源文件传输工具。官网地址:https://curl.haxx.se/

因为elasticsearch提供了标准的http接口,所以我们可以使用curl方便的访问elasticsearch。

下面收集了一些使用curl命令操作elasticsearch。

第一:_cat系列
_cat系列提供了一系列查询elasticsearch集群状态的接口。你可以通过执行

curl -XGET localhost:9200/_cat 获取所有_cat系列的操作

$ curl -XGET localhost:9200/_cat
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_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/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates

第二:_cluster系列
1、查询设置集群状态

curl -XGET localhost:9200/_cluster/health?pretty=true
  pretty=true表示格式化输出
  level=indices 表示显示索引状态
  level=shards 表示显示分片信息

2、显示集群系统信息,包括CPU、JVM等等

curl -XGET localhost:9200/_cluster/stats?pretty=true

3、 显示集群的详细信息,包括节点、分片等。

curl -XGET localhost:9200/_cluster/state?pretty=true

4、获取集群堆积的任务。

curl -XGET localhost:9200/_cluster/pending_tasks?pretty=true

5、修改集群配置
举例:

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

transient 表示临时的,persistent表示永久的
6、对shard的手动控制

curl -XPOST ‘localhost:9200/_cluster/reroute’ -d ‘xxxxxx’

参考http://zhaoyanblog.com/archives/687.html
7、关闭节点
例如:关闭指定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

参考原创链接地址:http://zhaoyanblog.com/archives/732.html

学习用Node.js和Elasticsearch构建搜索引擎(3):使用curl命令操作elasticsearch的更多相关文章

  1. 学习用Node.js和Elasticsearch构建搜索引擎(6):实际项目中常用命令使用记录

    1.检测集群是否健康. curl -XGET 'localhost:9200/_cat/health?v' #后面加一个v表示让输出内容表格显示表头 绿色表示一切正常,黄色表示所有的数据可用但是部分副 ...

  2. 使用curl命令操作elasticsearch

    使用curl命令操作elasticsearch 大岩不灿 发表于 2015年4月25日 浏览 7,426 次 第一:_cat系列_cat系列提供了一系列查询elasticsearch集群状态的接口.你 ...

  3. 学习用Node.js和Elasticsearch构建搜索引擎(1):了解并运行Elasticsearch

    1.学习Elasticsearch概述. 了解Elasticsearch是什么?能做什么?可以查一下elasticsearch.lucene等的相关介绍,另外也可以查查资料比较一下其它的搜索引擎sph ...

  4. 学习用Node.js和Elasticsearch构建搜索引擎(4): 构建Elasticsearch搜索引擎

    一.目标 使用node搭建一个知识库检索系统,要求词条平均检索速度必须在1s以内. 二.思路. 本人思路如下图. 橙色部分为我们要开发的内容, ES服务搭建(暂时用单节点测试,集群搭建以后再说), 三 ...

  5. 学习用Node.js和Elasticsearch构建搜索引擎(7):零停机时间更新索引配置或迁移索引

    上一篇说到如果一个索引的mapping设置过了,想要修改type或analyzer,通常的做法是新建一个索引,重新设置mapping,再把数据同步过来. 那么如何实现零停机时间更新索引配置或迁移索引? ...

  6. 学习用node.js建立一个简单的web服务器

    一.建立简单的Web服务器涉及到Node.js的一些基本知识点: 1.请求模块 在Node.js中,系统提供了许多有用的模块(当然你也可以用JavaScript编写自己的模块,以后的章节我们将详细讲解 ...

  7. 学习用Node.js和Elasticsearch构建搜索引擎(2):一些检索命令

    1.Elasticsearch搜索数据有两种方式. 一种方式是通过REST请求URI,发送搜索参数: 另一种是通过REST请求体,发送搜索参数.而请求体允许你包含更容易表达和可阅读的JSON格式.这个 ...

  8. 学习用Node.js和Elasticsearch构建搜索引擎(5):mac本机部署canal

    1.背景介绍 最近做的一个项目需要快速检索数据,经过商讨后采用了ElasticSearch作为快速检索数据引擎,但是数据如何同步到ES中是个问题,我们最开始计划了定时任务.mysql trigger等 ...

  9. ELK学习笔记之使用curl命令操作elasticsearch

    0x00 _cat系列 _cat系列提供了一系列查询elasticsearch集群状态的接口.你可以通过执行curl -XGET localhost:9200/_cat 1. 获取所有_cat系列的操 ...

随机推荐

  1. Keras实现卷积神经网络

    # -*- coding: utf-8 -*- """ Created on Sun Jan 20 11:25:29 2019 @author: zhen "& ...

  2. 【redis专题(9)】事务

    Redis支持简单的事务,所谓简单是因为其不支持回滚(回滚是用队列模仿的),与mysql有以下区别 rollback与discard的区别: 如果已经成功执行了2条语句, 第3条语句出错 Rollba ...

  3. Sql查询今天、本周和本月的记录(时间字段为时间戳)

    工作中遇到的问题,小结一下 查询今日添加的记录: select * from [表名] where datediff(day,CONVERT(VARCHAR(20),DATEADD(SECOND,[时 ...

  4. Python比较(关系)运算符

    比较(关系)运算符 运 算 符 作 用   举 例  结 果  >  大于 'a'>'b'   False  <  小于  156<456  True  ==  等于  'c' ...

  5. 全局Ajax加载时呈现Loading

    全局设置: 1 2 3 4 5 $(document).bind("ajaxSend", function () {         $("#loading_messag ...

  6. Windows Server 2016-Hyper-V 2016新增功能

    本文解释了Windows Server 2016和Microsoft Hyper-V Server 2016上Hyper-V的新增功能和变更功能. 与Connected Standby兼容(新) 在使 ...

  7. MySQL注入与防御

    1.简介 1.1.含义 在一个应用中,数据的安全无疑是最重要的.数据的最终归宿都是数据库,因此如何保证数据库不被恶意攻击者入侵是一项重要且严肃的问题! SQL注入作为一种很流行的攻击手段,一直以来都受 ...

  8. 【2018.05.11 智能驾驶/汽车电子】非技术向:关于Simulink和AutoSar的几种观点

    最近看到几篇关于Simulink及AutoSar的Blog和Paper,感觉比较有意思,转载备忘之. 1. 看衰Simulink及AutoSar From:Tumiz的技术天地 https://blo ...

  9. CSS鼠标悬浮DIV后显示DIV外的按钮

    昨天写样式遇到个问题,如何让鼠标悬浮DIV后,显示DIV外的按钮,可以点击到按钮. 效果如下: 问题: 在DIV hover时候将按钮设为display: block,这是很直接的想法,但是这有个问题 ...

  10. MySQL高级知识(十四)——行锁

    前言:前面学习了表锁的相关知识,本篇主要介绍行锁的相关知识.行锁偏向InnoDB存储引擎,开销大,加锁慢,会出现死锁,锁定粒度小,发生锁冲突的概率低,但并发度高. 0.准备 #1.创建相关测试表tb_ ...