在Kibana 7 / 6.7.2中设置过滤器,以获取DSL中大小为1的最新_id

时间:2019-04-17 13:49:50

标签: elasticsearch kibana

我希望在仪表板上设置过滤器,该仪表板将仅获取最新记录

因此在下面的DSL查询中使用

{
  "query": {
    "match_all": {}
  },
  "size": 1,
  "sort": [
    {
      "_id": {
        "order": "desc"
      }
    }
  ]
}

这在Elasticsearch Kibana 7.0中不起作用,我也已经在6.7.1中签入,它不起作用

"size" : 1 not working

当我在开发者工具中发布请求时,同样的方法

POST index/_search
{
   "query": {
        "match_all": {}
      },
      "size": 1,
      "sort": [
        {
          "_id": {
            "order": "desc"
          }
        }
      ]
}

但是它不适用于DSL查询。 参考:Get last document from ElasticSearch

Return the most recent record from ElasticSearch index

当我单击检查并检查请求时,我收到下面的请求,该请求没有我的尺寸过滤器

{
  "version": true,
  "size": 500,
  "sort": [
    {
      "timestamp": {
        "order": "desc",
        "unmapped_type": "boolean"
      }
    }
  ],
  "_source": {
    "excludes": []
  },
  "aggs": {
    "2": {
      "date_histogram": {
        "field": "timestamp",
        "interval": "12h",
        "time_zone": "Asia/Calcutta",
        "min_doc_count": 1
      }
    }
  },
  "stored_fields": [
    "*"
  ],
  "script_fields": {
    "StartTime": {
      "script": {
        "source": "return doc['timestamp'].value",
        "lang": "painless"
      }
    },
    "ExecDurn": {
      "script": {
        "source": "try{\n\tif (doc['endTime'].size() != 0 && doc['timestamp'].size() != 0) {\n\t\tChronoUnit.MILLIS.between(doc['timestamp'].value.toInstant(),doc['endTime'].value.toInstant())\n\t}\n}\ncatch (Exception ignored) {\n}",
        "lang": "painless"
      }
    },
    "EndTime": {
      "script": {
        "source": "try{\n\tif (doc['endTime'].size() != 0) {\n\t\tdoc['endTime'].value\n\t}\n\t}\ncatch (Exception ignored) {\n}",
        "lang": "painless"
      }
    }
  },
  "docvalue_fields": [
    {
      "field": "endTime",
      "format": "date_time"
    },
    {
      "field": "timestamp",
      "format": "date_time"
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "timestamp": {
              "format": "strict_date_optional_time",
              "gte": "2019-04-06T09:51:57.824Z",
              "lte": "2019-04-21T09:51:57.824Z"
            }
          }
        }
      ],
      "filter": [
        {
          "match_all": {}
        }
      ],
      "should": [],
      "must_not": []
    }
  },
  "highlight": {
    "pre_tags": [
      "@kibana-highlighted-field@"
    ],
    "post_tags": [
      "@/kibana-highlighted-field@"
    ],
    "fields": {
      "*": {}
    },
    "fragment_size": 2147483647
  }
}

1 个答案:

答案 0 :(得分:0)

默认情况下,“发现”视图将显示500条记录。您可以通过以下方法修改该设置:转到“管理”>“高级设置”,然后将“行数”设置更改为1。

number of rows