学习用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系列的操 ...
随机推荐
- mssql sqlserver null数据类型专题
摘要: 下文将详细讲述sql server NULL(空值)的相关知识,如下所示: 实验环境: sql server 2008 R2 NULL(空值)简介: mssql sqlserver null数 ...
- Windows Server 2016-Win Ser 2016新增功能
本来想着整个系列都是与Active Directory相关的内容,上一章节我们应读者要求补充了Window Server 2016标准版与数据中心版的区别,鉴于读者的疑惑,从本章节开始补充三到五章与W ...
- 关于svn上传.classpath等问题
1. svn版本:客户端版本与服务器版本 要尽量适配. 2. svn管理项目:有人将.classpath, .project, .mymetadata, .myumldata等文件也纳入到版本控制,如 ...
- CentOS更换源
这里介绍如何把CentOS默认镜像源更换为阿里云镜像源 1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.r ...
- Linux学习之路(一)
导语: 早前为了方便日常开发,建立跟生产环境类型的环境的时候考虑使用docker作为模拟生产环境,结果没想到给自己的学习挖了一个大坑.其他关于docker容器技术的坑先不在这里赘述,有时间的话在其他文 ...
- python入门练习题
1.使用while循环输入 1 2 3 4 5 6 8 9 10 num = 1 while num<=10: if num ==7: num += 1 continue print(n ...
- 【Teradata】数据库初始化(sysinit和dip工具)
1.删除数据库对象 (1)使用root用户登录数据库节点 arcmain .LOGON 127.0.0.1/dbc,dbc_password; (2)清理所有数据库对象及数据 DELETE DATAB ...
- ES6+Vue+webpack项目,在ie11中请求后台接口后数据更新,但是页面没有刷新?
因为ie11下,如果GET请求请求相同的URL,默认会使用之前请求来的缓存数据,而不会去请求接口获取最新数据,我用的解决方法是在每个请求发送前,拦截请求并给请求接口的URL后加一个时间戳(new Da ...
- MySQL高级知识(三)——索引
前言:索引在sql调优部分占据着重要的位置,了解并深入索引对我们来说也是非常重要的.本篇主要介绍MySQL中索引的相关知识点. 1.索引是什么 MySQL官方对索引的定义:索引(Index)是帮助My ...
- UVA1616-Caravan Robbers(二分)
Problem UVA1616-Caravan Robbers Accept: 96 Submit: 946Time Limit: 3000 mSec Problem Description Lon ...