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