学习用Node.js和Elasticsearch构建搜索引擎(3):使用curl命令操作elasticsearch
使用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的更多相关文章
- 学习用Node.js和Elasticsearch构建搜索引擎(6):实际项目中常用命令使用记录
1.检测集群是否健康. curl -XGET 'localhost:9200/_cat/health?v' #后面加一个v表示让输出内容表格显示表头 绿色表示一切正常,黄色表示所有的数据可用但是部分副 ...
- 使用curl命令操作elasticsearch
使用curl命令操作elasticsearch 大岩不灿 发表于 2015年4月25日 浏览 7,426 次 第一:_cat系列_cat系列提供了一系列查询elasticsearch集群状态的接口.你 ...
- 学习用Node.js和Elasticsearch构建搜索引擎(1):了解并运行Elasticsearch
1.学习Elasticsearch概述. 了解Elasticsearch是什么?能做什么?可以查一下elasticsearch.lucene等的相关介绍,另外也可以查查资料比较一下其它的搜索引擎sph ...
- 学习用Node.js和Elasticsearch构建搜索引擎(4): 构建Elasticsearch搜索引擎
一.目标 使用node搭建一个知识库检索系统,要求词条平均检索速度必须在1s以内. 二.思路. 本人思路如下图. 橙色部分为我们要开发的内容, ES服务搭建(暂时用单节点测试,集群搭建以后再说), 三 ...
- 学习用Node.js和Elasticsearch构建搜索引擎(7):零停机时间更新索引配置或迁移索引
上一篇说到如果一个索引的mapping设置过了,想要修改type或analyzer,通常的做法是新建一个索引,重新设置mapping,再把数据同步过来. 那么如何实现零停机时间更新索引配置或迁移索引? ...
- 学习用node.js建立一个简单的web服务器
一.建立简单的Web服务器涉及到Node.js的一些基本知识点: 1.请求模块 在Node.js中,系统提供了许多有用的模块(当然你也可以用JavaScript编写自己的模块,以后的章节我们将详细讲解 ...
- 学习用Node.js和Elasticsearch构建搜索引擎(2):一些检索命令
1.Elasticsearch搜索数据有两种方式. 一种方式是通过REST请求URI,发送搜索参数: 另一种是通过REST请求体,发送搜索参数.而请求体允许你包含更容易表达和可阅读的JSON格式.这个 ...
- 学习用Node.js和Elasticsearch构建搜索引擎(5):mac本机部署canal
1.背景介绍 最近做的一个项目需要快速检索数据,经过商讨后采用了ElasticSearch作为快速检索数据引擎,但是数据如何同步到ES中是个问题,我们最开始计划了定时任务.mysql trigger等 ...
- ELK学习笔记之使用curl命令操作elasticsearch
0x00 _cat系列 _cat系列提供了一系列查询elasticsearch集群状态的接口.你可以通过执行curl -XGET localhost:9200/_cat 1. 获取所有_cat系列的操 ...
随机推荐
- SQL SERVER中LIKE使用变量类型不同输出结果不一致解惑
一同事在写脚本时,遇到一个关于LIKE里面使用不同的变量类型导致查询结果不一致的问题,因为这个问题被不同的人问过好几次,索性总结一下,免得每次都要解释一遍,直接丢一篇博客岂不是更方便!其实看似有点让人 ...
- MS SQL批量生成作业脚本方法介绍总结
在迁移或升级SQL Server数据库服务器时,很多场景下我们不能还原msdb,所以我们必须手工迁移SQL Server相关作业.如果手工生成每一个作业的脚本话,费时又费力,其实SQL Server中 ...
- springmvc复习笔记----文件上传multipartResolver
结构 web.xml <?xml version="1.0" encoding=&q ...
- C#-方法(八)
方法是什么 方法是C#中将一堆代码进行进行重用的机制 他是在类中实现一种特定功能的代码块,将重复性功能提取出来定义一个新的方法 这样可以提高代码的复用性,使编写程序更加快捷迅速 方法格式 访问修饰符 ...
- 前后端分离djangorestframework——分页组件
Pagination 为什么要分页也不用多说了,大家都懂,DRF也自带了分页组件 这次用 前后端分离djangorestframework——序列化与反序列化数据 文章里用到的数据,数据库用的my ...
- 自动化测试基础篇--Selenium Xpath定位
摘自https://www.cnblogs.com/sanzangTst/p/7458056.html 学习 什么是xpath? XPath即为XML路径语言,它是一种用来确定XML(标准通用标记语言 ...
- hive笔记:复杂数据类型-array结构
array 结构 (1)语法:array(val1,val2,val3,…) 操作类型:array array类型的数据可以通过'数组名[index]'的方式访问,index从0开始: (2)建表: ...
- Java的基础知识四
一.Java 流(Stream).文件(File)和IO Java.io 包几乎包含了所有操作输入.输出需要的类.所有这些流类代表了输入源和输出目标. Java.io 包中的流支持很多种格式,比如:基 ...
- Vmware12安装centos系统详解
vmware12安装centos7系统详解 用虚拟机12安装centos7系统详细安装过程,后附centos7下载地址. 工具/原料 虚拟机12 centos7系统镜像 方法/步骤 1 1.百度搜索c ...
- 【大数据技术】Sqoop
1.Sqoop是什么 Sqoop:SQL-to-Hadoop,传统数据库与Hadoop间数据同步工具.(MySQL.Oracle <==> HDFS.HBase.Hive) Sqoop ...