参考链接

Relational DB Elasticsearch
数据库(database) 索引(indices)
表(tables) types
行(rows) documents
字段(columns) fields

库表行字段,index,type,id,fields,  索引类型文档字段

创建一篇文档

PUT t1/doc/1
{
"name": "小黑的小姨妈",
"age": 18
}

index/type/id  id是单个文档

查询所有索引

GET _cat/indices?v

查询指定的索引信息

GET t1

查询文档信息

GET t1/doc/1           #查询指定文档
GET t1/doc/_search #查询所有文档

删除指定索引

DELETE /t1

修改文档

PUT zhifou/doc/1
{
"name":"顾老二",
"age":30,
"from": "gu",
"desc": "皮肤黑、武器长、性格直",
"tags": ["黑", "长", "直"]
} 我们要将黑修改成黄:
POST zhifou/doc/1/_update
{
"doc": {
"desc": "皮肤很黄,武器很长,性格很直",
"tags": ["很黄","很长", "很直"]
}
}

查询字符串

方式一:
GET zhifou/doc/_search?q=from:gu
属性是from,属性值是gu的文档 方式二:
GET zhifou/doc/_search
{
"query": {
"match": {
"from": "gu"
}
}
}

match条件查询,查询含有(匹配)指定字段值的文档

我们查看来自顾家的都有哪些人

GET zhifou/doc/_search
{
"query": {
"match": {
"from": "gu"
}
}
}

match查询全部文档

查询zhifou索引下的doc类型中的所有文档,那就是查询全部

GET zhifou/doc/_search
{
"query": {
"match_all": {}
}
}

match_phrase(短语查询)

GET t1/doc/_search
{
"query": {
"match_phrase": {
"title": {
"query": "中国"
}
}
}
} title字段中包含短语中国
GET t1/doc/_search
{
"query": {
"match_phrase": {
"title": {
"query": "中国世界",
"slop": 2
}
}
}
}
slop了。相当于正则中的中国.*?世界。这个间隔默认为0,指定短语间隔

match_phrase_prefix(最左前缀查询)

GET t3/doc/_search
{
"query": {
"match_phrase_prefix": {
"desc": "bea"
}
}
}
desc字段bea开头字
GET t3/doc/_search
{
"query": {
"match_phrase_prefix": {
"desc": {
"query": "bea",
"max_expansions": 1
} }
}
}
max_expansions来设置最大的前缀扩展数量

multi_match(多字段查询)

方法一:
GET t3/doc/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "beautiful"
}
},
{
"match": {
"desc": "beautiful"
}
}
]
}
}
} 方法二:
GET t3/doc/_search
{
"query": {
"multi_match": {
"query": "beautiful",
"fields": ["title", "desc"]
}
}
} multi_match甚至可以当做match_phrase和match_phrase_prefix使用,只需要指定type类型即可:
GET t3/doc/_search
{
"query": {
"multi_match": {
"query": "gi",
"fields": ["title"],
"type": "phrase_prefix"
}
}
}
GET t3/doc/_search
{
"query": {
"multi_match": {
"query": "girl",
"fields": ["title"],
"type": "phrase"
}
}
}

term查询#单个匹配项

POST _analyze
{
"analyzer": "standard",
"text": "Beautiful girl!"
}
# 结果
["beautiful", "girl"] GET w10/doc/_search
{
"query": {
"term": {
"t1": "beautiful"
}
}
}

terms查询#多个匹配项

GET w10/doc/_search
{
"query": {
"terms": {
"t1": ["beautiful", "sexy"]
}
}
}

排序查询:sort#按某个字段降序查询

查询顾府都有哪些人,并根据age字段按照降序

GET zhifou/doc/_search
{
"query": {
"match": {
"from": "gu"
}
},
"sort": [
{
"age": {
"order": "desc"
}
}
]
}

按某个字段升序查询

GET zhifou/doc/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"age": {
"order": "asc"
}
}
]
}

分页查询:from/size#

GET zhifou/doc/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"age": {
"order": "desc"
}
}
],
"from": 2,
"size": 1
} from:从哪开始查
size:返回几条结果

bool查询

must#(and)并且,满足多个条件

单个条件查询:布尔查询所有from属性为gu的数据:
GET zhifou/doc/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"from": "gu"
}
}
]
}
}
}
多个条件查询:想要查询from为gu,并且age为30的数据
GET zhifou/doc/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"from": "gu"
}
},
{
"match": {
"age": 30
}
}
]
}
}
}

bool查询should(or),满足一个就行

查询只要是from为gu或者tags为闭月的数据
GET zhifou/doc/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"from": "gu"
}
},
{
"match": {
"tags": "闭月"
}
}
]
}
}
}

bool查询must_not(not)  既不,也不是

查询from既不是gu并且tags也不是可爱,还有age不是18的数据
GET zhifou/doc/_search
{
"query": {
"bool": {
"must_not": [
{
"match": {
"from": "gu"
}
},
{
"match": {
"tags": "可爱"
}
},
{
"match": {
"age": 18
}
}
]
}
}
}

bool查询filter  满足某个条件,某个字段还可以比较大小范围

查询from为gu,age大于25的数据 。比较符号有gt gte lt lte
GET zhifou/doc/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"from": "gu"
}
}
],
"filter": {
"range": {
"age": {
"gt": 25
}
}
}
}
}
} 查询from是gu,age在25~30之间
GET zhifou/doc/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"from": "gu"
}
}
],
"filter": {
"range": {
"age": {
"gte": 25,
"lte": 30
}
}
}
}
}
}
must改成should,满足下面的filter但不满足上面的match也会显示出来
GET zhifou/doc/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"from": "sheng"
}
}
],
"filter": {
"range": {
"age": {
"lte": 25
}
}
}
}
}
}

bool must filter过滤,过滤一个字段是a,并且另一个字段是b或者c

GET xxx-fsmxx_pm_rawxx_mod_unix_linux_211128/_doc/_search
{
"query": {
"bool": {
"must": [{
"range": {
"DCTIME": {
"from": 1,
"to": 1738028800000,
"include_lower": false,
"include_upper": false,
"boost": 1.0
}
}
}],
"filter": [{
"terms": {
"KPI_NO": ["20200413185034"],
"boost": 1.0
}
}, {
"terms": {
"KBP": ["6518921118106698111","6038954760944889699"]
}
}],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"sort": [{
"DCTIME": {
"order": "asc",
"unmapped_type": "long"
}
}]
}
  • must:与关系,相当于关系型数据库中的and
  • should:或关系,相当于关系型数据库中的or
  • must_not:非关系,相当于关系型数据库中的not
  • filter:过滤条件。
  • range:条件筛选范围。
  • gt:大于,相当于关系型数据库中的>
  • gte:大于等于,相当于关系型数据库中的>=
  • lt:小于,相当于关系型数据库中的<
  • lte:小于等于,相当于关系型数据库中的<=

结果过滤:_source

在所有的结果中,我只需要查看name和age两个属性,其他的不要
GET zhifou/doc/_search
{
"query": {
"match": {
"name": "顾老二"
}
},
"_source": ["name", "age"]
}

avg

查询from是gu的人的平均年龄
GET zhifou/doc/_search
{
"query": {
"match": {
"from": "gu"
}
},
"aggs": {
"my_avg": {
"avg": {
"field": "age"
}
}
},
"_source": ["name", "age"]
}
首先匹配查询from是gu的数据。在此基础上做查询平均值的操作,这里就用到了聚合函数,其语法被封装在aggs中,而my_avg则是为查询结果起个别名,封装了计算出的平均值。那么,要以什么属性作为条件呢?是age年龄,查年龄的什么呢?是avg,查平均年龄。 只想看平均值
GET zhifou/doc/_search
{
"query": {
"match": {
"from": "gu"
}
},
"aggs": {
"my_avg": {
"avg": {
"field": "age"
}
}
},
"size": 0,
"_source": ["name", "age"]
}

max

GET zhifou/doc/_search
{
"query": {
"match": {
"from": "gu"
}
},
"aggs": {
"my_max": {
"max": {
"field": "age"
}
}
},
"size": 0
}

min

GET zhifou/doc/_search
{
"query": {
"match": {
"from": "gu"
}
},
"aggs": {
"my_min": {
"min": {
"field": "age"
}
}
},
"size": 0
}

sum

GET zhifou/doc/_search
{
"query": {
"match": {
"from": "gu"
}
},
"aggs": {
"my_sum": {
"sum": {
"field": "age"
}
}
},
"size": 0
}

分组查询和分组聚合

查询所有人的年龄段,并且按照15~20,20~25,25~30分组,
GET zhifou/doc/_search
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"age_group": {
"range": {
"field": "age",
"ranges": [
{
"from": 15,
"to": 20
},
{
"from": 20,
"to": 25
},
{
"from": 25,
"to": 30
}
]
}
}
}
} 查询所有人的年龄段,并且按照15~20,20~25,25~30分组,并且算出每组的平均年龄。每个小组内的数据做平均年龄处理。
GET zhifou/doc/_search
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"age_group": {
"range": {
"field": "age",
"ranges": [
{
"from": 15,
"to": 20
},
{
"from": 20,
"to": 25
},
{
"from": 25,
"to": 30
}
]
},
"aggs": {
"my_avg": {
"avg": {
"field": "age"
}
}
}
}
}
}

curl方法查看es集群信息:

现场磁盘空间使用情况查询
curl -XGET -u 用户:密码 "http://ip:端口/_cat/nodes?v&h=http,version,jdk,disk.total,disk.used,disk.avail,disk.used_percent,heap.current,heap.percent,heap.max,ram.current,ram.percent,ram.max,master"
好像是查看所有索引分片的吧,反正是一大片输出:
curl -XGET -u 用户:密码 "http://ip:端口/_cat/shards?v"
查看集群状态:
curl -XGET -u 用户:密码 -H "Content-Type: application/json" http://ip:端口/_cat/health?v

  

es命令大全,elasticsearch命令详解的更多相关文章

  1. linux管道命令grep命令参数及用法详解---附使用案例|grep

    功能说明:查找文件里符合条件的字符串. 语 法:grep [-abcEFGhHilLnqrsvVwxy][-A<显示列数>][-B<显示列数>][-C<显示列数>] ...

  2. linux mount命令参数及用法详解

    linux mount命令参数及用法详解 非原创,主要来自 http://www.360doc.com/content/13/0608/14/12600778_291501907.shtml. htt ...

  3. 【转】linux expr命令参数及用法详解

    在抓包过程中,查看某个设定时间内,数据上下行多少,用命令expr 计算! --------------------------------------------------------------- ...

  4. linux useradd(adduser)命令参数及用法详解(linux创建新用户命令)

    linux useradd(adduser)命令参数及用法详解(linux创建新用户命令) useradd可用来建立用户帐号.帐号建好之后,再用passwd设定帐号的密码.而可用userdel删除帐号 ...

  5. linux dmesg命令参数及用法详解(linux显示开机信息命令)

    linux dmesg命令参数及用法详解(linux显示开机信息命令) http://blog.csdn.net/zhongyhc/article/details/8909905 功能说明:显示开机信 ...

  6. linux sed命令参数及用法详解

    linux sed命令参数及用法详解 http://blog.csdn.net/namecyf/article/details/7336308 1. Sed简介 sed 是一种在线编辑器,它一次处理一 ...

  7. Linux Bash命令关于程序调试详解

    转载:http://os.51cto.com/art/201006/207230.htm 参考:<Linux shell 脚本攻略>Page22-23 Linux bash程序在程序员的使 ...

  8. linux dd命令参数及用法详解---用指定大小的块拷贝一个文件(也可整盘备份)

    linux dd命令参数及用法详解---用指定大小的块拷贝一个文件 日期:2010-06-14 点击:3830 来源: 未知 分享至:            linux dd命令使用详解 dd 的主要 ...

  9. (转)linux expr命令参数及用法详解

    linux expr命令参数及用法详解 原文:http://blog.csdn.net/tianmohust/article/details/7628694 expr用法 expr命令一般用于整数值, ...

  10. (转)Linux命令之Ethtool用法详解

    Linux命令之Ethtool用法详解 原文:http://www.linuxidc.com/Linux/2012-01/52669.htm Linux/Unix命令之Ethtool描述:Ethtoo ...

随机推荐

  1. C++ 编译器和链接器的完全指南

    C++是一种强类型语言,它的编译和链接是程序开发过程中不可或缺的两个环节.编译器和链接器是两个非常重要的概念.本文将详细介绍C++中的编译器和链接器以及它们的工作原理和使用方法. 编译器 编译器是将源 ...

  2. Grafana系列-统一展示-10-Explore Jaeger

    系列文章 Grafana 系列文章 Explore Jaeger 你可以通过Explore查询和显示 Jaeger 的 trace.有 3 种方法: Query by search Query by ...

  3. 掌握 xUnit 单元测试中的 Mock 与 Stub 实战

    引言 上一章节介绍了 TDD 的三大法则,今天我们讲一下在单元测试中模拟对象的使用. Fake Fake - Fake 是一个通用术语,可用于描述 stub或 mock 对象. 它是 stub 还是 ...

  4. go语言结构体使用小结

    转载请注明出处: 在Go语言中,结构体(struct)是一种复合数据类型,它允许你将多个不同类型的字段组合成一个单一的类型.结构体为数据的封装和抽象提供了便利,使得数据组织更加清晰和易于管理. 结构体 ...

  5. 重新整理 .net core 实践篇—————grpc工具[三十四]

    前言 简单整理一下grpc工具. 正文 工具核心包: Grpc.Tools 这个是项目要引用的包,用来生成cs代码的. dotnet-grpc 这个就是cli,命令行工具 dotnet-grpc 核心 ...

  6. 【笔记】GO内建容器--数组

    go内建容器--数组 1.数量要写在类型的前面 2.可通过_省略变量 3.不仅是range,任何地方都可以使用_来省略变量 4.如果只要i,则可写成for i := range numbers 5.[ ...

  7. 超大福利 | 这款免费 Java 在线诊断利器,不用真的会后悔!

    线上系统为何经常出错?数据库为何屡遭黑手?业务调用为何频频失败?连环异常堆栈案,究竟是哪次调用所为? 数百台服务器意外雪崩背后又隐藏着什么?是软件的扭曲还是硬件的沦丧? 走进科学带你了解 Arthas ...

  8. [FAQ] Docker查询出所有的停止容器并移除

    $ docker rm `docker container ls -a --filter "status=exited" | awk '{print $1}' | sed '1,1 ...

  9. 重回铁王座!时隔5年!Quill 2.0 终于发布啦🎉

    你好,我是 Kagol. 2024年4月17日,Quill 2.0 正式发布 最后一个 1.0 版本 1.3.7 发布于 2019年9月9日,时隔4年零7个月. 富文本编辑器拥有非常丰富的使用场景,我 ...

  10. WPF 如何在静态资源定义字体大小

    默认的 WPF 的字体大小的单位是像素,如果想要将字体大小使用 pt 点表示,写在 xaml 里面是直接添加 pt 后缀.但是此时如果在静态资源尝试定义的时候写上了 pt 将会在运行的时候提示无法转换 ...