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 keyword text自动分词,keyword全文匹配
整型 byte short integer long
浮点型 float double half_float scaled_float
日期 date
布尔 boolean
二进制 binary
范围 range
数组 array
对象 object
嵌套 nested
ip ip (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"
      }
    }
  }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM