kibana 查询ES 的一些语法

前言

不断增补ing

版本 7.8.0

替换的关键字使用中文说明,根据需求自行替换


正文

基础知识

命令

-7.x中的type已经过时,默认设置为_doc

命令url解释
put/索引名称/类型名称/文档ID创建文档(指定文档ID)
POST/索引名称/索引类型创建文档(随机文档ID)
POST/索引名称/类型名称/文档id/_update修改文档
POST/索引名称/类型名称/_search查询数据
DELETE/索引名称/类型名称/文档id删除文档/或者索引
GET/索引名称/类型名称/文档id查询文档通过文档ID

字段类型

类型对应类型说明
字符串text keywordtext自动分词,keyword全文匹配
整型byte short integer long
浮点型float double half_float scaled_float
日期date
布尔boolean
二进制binary
范围range
数组array
对象object
嵌套nested
ipip (IPv4 和 IPv6 地址)

创建

PUT index名

添加数据

POST index名/_doc
{
  你要添加的内容
}

删除

DELETE index名

查全部 match_all

GET index名/_search?pretty
{
  "query": {
    "match_all": {}
  }
}

单条件模糊查询 match

GET index名/_search?pretty
{
  "query": {
    "match": {
      "字段": "条件内容"
    }
  }
}

精确查询 term

GET index名/_search?pretty
{
  "query": {
    "term": {
      "字段": "条件内容"
    }
  }
}

单条件模糊查询 match

  • 指定查询条数,类似于sql的分页 from size
GET index名/_search?pretty
{
  "from": 0, 
  "size": 2, 
  "query": {
    "match": {
      "字段": "条件内容"
    }
  }
}

单条件模糊查询 match

  • 限制返回的字段 _source
GET /atlas_cloud_logs/_search?pretty
{
  "from": 0, 
  "size": 2, 
  "_source": ["字段"],
  "query": {
    "match": {
      "字段": "条件内容"
    }
  }
}

filter过滤

  • gte 大于等于
  • lte 小于等于
  • e 等于
  • bool
    • must 必须
    • should 或者
    • must_not 不等于
GET index名/_search?pretty
{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "过滤的字段": {
            "gte": 10, 
            "lte": 200
          }
        }
      }
    }
  }
}

聚合查询 aggs

GET /atlas_cloud_logs/_search?pretty
{
  "size": 0, 
  "query": {
   "match_all": {
   }
  },
  "aggs": {
    "聚合后返回的关键字": {
      "terms": {
        "field": "聚合字段.keyword"
      }
    }
  }
}
  • 1
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值