elasticsearch 常用command

elasticsearch常用命令

检查es版本信息

curl IP:9200

查看集群是否健康

http://IP:9200/_cat/health?v

curl 'IP:9200/_cat/health?v'

查看节点列表

http://IP:9200/_cat/nodes?v

curl 'IP:9200/_cat/nodes?v'

列出所有索引及存储大小

http://IP:9200/_cat/indices?v

curl 'IP:9200/_cat/indices?v'--查询所有索引及数据大小

创建索引

创建索引名为XX,默认会有5个分片,1个索引

curl -XPUT 'IP:9200/XX?pretty'

删除指定索引

curl -XDELETE 'IP:9200/_index?pretty'

添加一个类型

curl -XPUT 'IP:9200/XX/external/2?pretty' -d '

{

"gwyy": "John"

}'

更新一个类型

curl -XPOST 'IP:9200/XX/external/1/_update?pretty' -d '

{

"doc": {"name": "Jaf"}

}'

文档删除-单个: curl -XDELETE 'localhost:9200/XX/external/1?pretty'

删除为1的文档

文档删除-多个:
curl -XDELETE 'localhost:9200/customer/external/_query?pretty' -d '
{
"query": { "match": { "name": "John Doe" } }
}'

注:首先查询出所有name为John Doe的,然后一起删除


文档批处理-创建:创建一个Id为21和22的文档
curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
{"index":{"_id":"21"}}
{"name": "John Doe" }
{"index":{"_id":"22"}}
{"name": "Jane Doe" }  '

[[email protected] ~]#  curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '

>         {"index":{"_id":"21"}}

>         {"name": "John Doe" }

>         {"index":{"_id":"22"}}

>         {"name": "Jane Doe" }

>         '

{

"took" : 35,

"errors" : false,

"items" : [

{

"index" :

{

"_index" : "customer",

"_type" : "external",

"_id" : "21",

"_version" : 1,

"result" : "created",

"_shards" : {

"total" : 2,

"successful" : 1,

"failed" : 0

},

"created" : true,

"status" : 201

}

},

{

"index" :

{

"_index" : "customer",

"_type" : "external",

"_id" : "22",

"_version" : 1,

"result" : "created",

"_shards" :

{

"total" : 2,

"successful" : 1,

"failed" : 0

},

"created" : true,

"status" : 201

}

}

]

}

文档批处理:一个更新,一个删除
curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
{"update":{"_id":"21"}}
{"doc": { "name": "Jimmy" } }
{"delete":{"_id":"22"}}
'

参考https://www.jianshu.com/p/1e9e51454aa5

原文地址:http://blog.51cto.com/lookingdream/2118613

时间: 2024-08-30 00:37:31

elasticsearch 常用command的相关文章

Windows常用command line操作

使用command line的优势在于: 速度比GUI更快 有一些软件和工具只能通过command line进行操作 目录 1. 改变目录 2. 列出文件和目录 [Tab自动补全目录名] 3. 打开文件 [清空界面,筛选文件格式,/? 命令提示符] 4. 创建和移除目录 5. 关于路径PATH 6. 关于Drives [tree:改变cmd的颜色] 7. 文件属性 8. 删除和读取文件 9. 复制和移动文件 常用command line操作: 改变目录 每当我们运行cmd [右击windows-

ElasticSearch常用结构化搜索

最近,需要用到ES的一些常用的结构化搜索命令,因此,看了一些官方的文档,学习了一下.结构化查询指的是查询那些具有内在结构的数据,比如日期.时间.数字都是结构化的. 它们都有精确的格式,我们可以对这些数据进行逻辑操作,比较常见的操作包括比较时间区间,或者获取两个数字间的较大值. 精确查询 当进行精确查询时,过滤器filter是十分重要的,因为它们效率非常高,过滤器不计算相关性(直接跳过了整个记分阶段)而且很容易进行缓存. 过滤数字 我们首先看 term filter,它最常用,可以用来处理数字,布

ElasticSearch 常用的查询过滤语句

query 和  filter 的区别请看: http://www.cnblogs.com/ghj1976/p/5292740.html    Filter DSL   term 过滤 term主要用于精确匹配哪些值,比如数字,日期,布尔值或 not_analyzed 的字符串(未经分析的文本数据类型): { "term": { "age":    26           }} { "term": { "date":   &

Elasticsearch常用操作:映射篇

[TOC] 其实就是es的字段类型是由es来做自动检测还是由我们自己来指定,因此会分为动态映射和静态映射. 1 动态映射 1.1 映射规则 JSON格式的数据 自动推测的字段类型 null 没有字段被添加 true or false boolean类型 浮点类型数字 float类型 数字 long类型 JSON对象 object类型 数组 由数组中第一个非空值决定 string 有可能是date类型(开启日期检测).double或long类型.text类型.keyword类型 1.2 日期检测

Elasticsearch 常用基本查询

安装启动很简单,参考官网步骤:https://www.elastic.co/downloads/elasticsearch 为了介绍Elasticsearch中的不同查询类型,我们将对带有下列字段的文档进行搜索:title(标题),authors(作者),summary(摘要),release date(发布时间)以及number of reviews(评论数量),首先,让我们创建一个新的索引,并通过bulk API查询文档: 为了展示Elasticsearch中不同查询的用法,首先在Elast

elasticsearch 常用命令

4 [[email protected]:bin]#curl -XGEt http://10.0.2.15:9200/_cluster/health 5 关闭整个集群 6 [[email protected]:bin]#curl -XPOST http://10.0.2.15:9200/_cluster/nodes/_shutdown?pretty 7 关闭单个节点 8 [[email protected]:bin]#curl -XPOST http://10.0.2.15:9200/_clus

Elasticsearch常用操作API

1. 查询所有的索引 [[email protected] cx]# curl '10.0.0.5:9200/_cat/indices?v' health status index    pri rep docs.count docs.deleted store.size pri.store.size  yellow open   customer   5   1          2            0      6.6kb          6.6kb  yellow open   b

Elasticsearch常用插件(三)

---恢复内容开始--- elasticsearch-head 一个elasticsearch的集群管理工具,它是完全由html5编写的独立网页程序,你可以通过插件把它集成到es. 项目地址:https://github.com/mobz/elasticsearch-head 插件安装方法1: 1 elasticsearch/bin/plugin install mobz/elasticsearch-head 2 重启elasticsearch 3 打开http://localhost:9200

elasticsearch常用操作

3.3.1 Preparing a query 准备查询请求 import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.search.SearchHit; SearchResponse response = client.prepareSearch("library") .addFields("t