簡體   English   中英

從Kibana獲取Elasticsearch查詢

[英]Obtaining an elasticsearch query from Kibana

我想將以下kibbana elasticsearch查詢轉換為elasticsearch.count elasticsearch.count(index=indices, body=query)

目標是獲取給定時間戳記(過去24小時),cluster和integer_field> 0的計數。

  • 時間戳:日期類型
  • 群集:字符串
  • integer_field:長整數(值通常是更大的整數)

正在查詢(從Kibana獲取)

curl -XGET 'some-url:9200/logstash-2015.07.03,logstash-2015.07.02/_search?pretty' -d '{
  "facets": {
    "0": {
      "date_histogram": {
        "field": "@timestamp",
        "interval": "10m"
      },
      "global": true,
      "facet_filter": {
        "fquery": {
          "query": {
            "filtered": {
              "query": {
                "query_string": {
                  "query": "*"
                }
              },
              "filter": {
                "bool": {
                  "must": [
                    {
                      "range": {
                        "@timestamp": {
                          "from": 1435840604940,
                          "to": 1435927004940
                        }
                      }
                    },
                    {
                      "fquery": {
                        "query": {
                          "query_string": {
                            "query": "integer_field:(>0)"
                          }
                        },
                        "_cache": true
                      }
                    },
                    {
                      "fquery": {
                        "query": {
                          "query_string": {
                            "query": "cluster:(\"YYY\")"
                          }
                        },
                        "_cache": true
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "size": 0
}'

對於其他情況,我有書面查詢。 只是這種情況,我被困住了。 幫助將不勝感激。

您要查找的查詢比強迫Kibana自動生成的查詢更簡單。 一般來說,從Kibana提取它們時,您要查找“過濾的”查詢部分。 從那里,您可以刪除通配符條件。

{
  "query": {
    "filtered": {
      "filter": {
        "bool" : {
          "must" : [
            {
              "term" : {
                "cluster" : "YYYY"
              }
            },
            {
              "range" : {
                "integer_field" : {
                  "gt" : 0
                }
              }
            },
            {
              "range" : {
                "@timestamp" : {
                  "gt" : "now - 24h"
                }
              }
            }
          ]
        }
      }
    }
  }
}

“群集” term過濾器是唯一可能對您的使用無效的過濾器。 term過濾器與索引值完全匹配,因此,如果它不是字面意義上的“ YYYY”(例如“ yyyy”),則將不匹配。 您可能希望{ "term": { ... } }為:

{
  "fquery" : {
    "query" : {
      "match" : {
        "cluster" : "YYYY"
      }
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM