es常见查询
ES集群管理
ES提供了一套_cat API, 可以查看ES中的各类数据.
多条件查询
1.关键词:"china"
2.发布时间:"2021-09-13 00:00:00","2021-09-22 13:42:27"
3.排除站点:aol.com
4.排除国建:中国-CHN
GET /new*/_count
{
"query":{
"bool":{
"must":[
{
"term":{
"text":{
"value":"china"
}
}
},{
"term": {
"mediaLevel": {
"value": "5"
}
}
}
],
"must_not": [
{
"term": {
"countryCode": {
"value": "CHN"
}
}
},
{
"term": {
"domain": {
"value": "aol.com"
}
}
}
],
"filter":{
"range":{
"pubTime":{
"gte":1631462400000,
"lte":16322893470007
}
}
}
}
}
}
多条件分组查询
1.查询以上条件,并且按照sourceType进行分组:
GET /new*/_search
{
"query":{
"bool":{
"must":[
{
"term":{
"text":{
"value":"china"
}
}
}
],
"must_not": [
{
"term": {
"countryCode": {
"value": "CHN"
}
}
},
{
"term": {
"domain": {
"value": "aol.com"
}
}
}
],
"filter":{
"range":{
"pubTime":{
"gte":1631462400000,
"lte":16322893470007
}
}
}
}
},
"size":0,
"aggs": {
"group_by_sourceType": {
"terms": {
"field": "sourceType",
"order": {
"_count": "asc"
}
}
}
}
}
查询某一个字段不为空
extend不为空
GET /social_user/_search
{
"query": {
"bool": {
"must": {
"exists": {
"field": "extend"
}
}
}
}
}
in or not in查询
GET /news*/_search
{
"query": {
"terms": {
"siteUrls": [
"https://www.bechtel.com/newsroom/releases/",
"https://www.bechtel.com/newsroom/coverage/"
]
}
},
"aggs": {
"distinct_sourcetype": {
"terms": {
"field": "sourceType"
}
}
},
"stored_fields": ["sourceType","siteUrls"]
}
多条件聚合
GET /news*/_search
{
"query": {
"terms": {
"siteUrls": [
"https://www.rolls-royce.com/media/press-releases.aspx"
]
}
},
"aggs": {
"distinct_sourcetype": {
"terms": {
"field": "sourceType"
}
},
"max_aggs":{
"max": {
"field": "pubTime"
}
},
"min_ahhs":{
"min": {
"field": "pubTime"
}
}
},
"stored_fields": ["sourceType","siteUrls","pubTime"]
}
ES针对于text类型的数据进行模糊匹配查询使用:query_string
系统日志存储在es的logstash下,然后是每天生成一个日志,其对应的mapping如下:
"logstash-2021.10.28" : {
"mappings" : {
"properties" : {
"class" : {
"type" : "keyword"
},
"kubernetes" : {
"properties" : {
"container_hash" : {
"type" : "keyword"
},
"container_image" : {
"type" : "keyword"
},
"container_name" : {
"type" : "keyword"
},
"docker_id" : {
"type" : "keyword"
},
"host" : {
"type" : "keyword"
},
"namespace_name" : {
"type" : "keyword"
},
"pod_id" : {
"type" : "keyword"
},
"pod_name" : {
"type" : "text"
}
}
},
"level" : {
"type" : "keyword"
},
"log" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"log_flie_path" : {
"type" : "text"
},
"log_time" : {
"type" : "keyword"
},
"message" : {
"type" : "text"
},
"source" : {
"type" : "keyword"
},
"stream" : {
"type" : "keyword"
},
"thread" : {
"type" : "text"
},
"time" : {
"type" : "date",
"format" : "strict_date_optional_time_nanos"
},
"timestamp" : {
"type" : "date"
}
}
}
}
查询日志如下:
GET /logstash-2021.11.10/_search
{
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "kubernetes.pod_name",
"query": "\"gtcom-governance-news-k8s-kafka-test-taskmanager\""
}
}
],
"filter": [
{
"term": {
"level": "ERROR"
}
}
]
}
},
"sort": [
{
"timestamp": {
"order": "desc"
}
}
],
"_source": ["message","level","kubernetes.pod_name"]
}
根据日期聚合查询
GET /news*/_search
{
"query": {
"bool": {
"filter": [
{
"range": {
"createTime": {
"gte": "2021-11-01"
}
}
}
]
}
},
"aggs": {
"NAME": {
"date_histogram": {
"field": "createTime",
"interval": "day"
}
}
}
}
推荐阅读
阿里云https免费证书申请
项目牵涉到做一个语音在线实时收集,然后进行asr识别的B/S应用。所以需要浏览器调用“麦克风”来获取用户语音。此时需要在localhost或者https下才能实现这样的功能。类似于google的语音翻译,如下所示:
startshineye阅读 230
ElasticSearch必知必会-基础篇
定义: 相同文档结构(Mapping)文档的结合 由唯一索引名称标定 一个集群中有多个索引 不同的索引代表不同的业务类型数据 注意事项: 索引名称不支持大写 索引名称最大支持255个字符长度 字段的名称,支持大写,...
京东云开发者赞 2阅读 544
ElasticSearch 必知必会 - 进阶篇
京东物流:康睿 姚再毅 李振 刘斌 王北永说明:以下全部均基于 ElasticSearch 8.1 版本一.跨集群检索 - ccr官网文档地址: [链接]跨集群检索的背景和意义跨集群检索定义跨集群检索环境搭建官网文档地址: [链接]...
京东云开发者赞 2阅读 503
ELK设置密码
为ELK配置密码访问, 以docker镜像sebp/elk为例所有文件目录参考链接:Docker安装ELK8.x1. 生成证书进入docker容器: docker exec -it elk /bin/bash进入ES的bin目录: cd /opt/elasticsearch/bin生成ca文件,./ela...
YYGP阅读 1.3k
elasticsearch(1)- 入门
平时项目开发中,经常会遇到模糊搜索的需求。通常当需要模糊搜索的数据库字段不大,我们可以简单通过 字段名 like '%搜索值%'实现,搜索效率不高,而且就算加索引也无法生效。对于数据库字段很大的,mysql还提供...
KerryWu阅读 1.1k
elasticsearch实现基于拼音搜索
一般情况下,有些搜索需求是需要根据拼音和中文来搜索的,那么在elasticsearch中是如何来实现基于拼音来搜索的呢?可以通过elasticsearch-analysis-pinyin分析器来实现。
huan1993阅读 967
elastic学习-elasticsearch8.5启动控制台内容
[toc]1. 不生成证书直接启动1.1 完整的控制台信息直接启动后控制台会展示记录一段关键信息 {代码...} 1.2 整体说明elastic账号的默认密码HTTP CA证书kibana访问es的token其他node加入当前node的cluster的token1.3...
风雪十年灯阅读 960
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。