Skip to content

Instantly share code, notes, and snippets.

@pindlebot
Last active July 26, 2019 02:19
Show Gist options
  • Save pindlebot/68e7c39e73e820d8ec0b6c09421694cd to your computer and use it in GitHub Desktop.
Save pindlebot/68e7c39e73e820d8ec0b6c09421694cd to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch')
const AUTH_TOKEN = ''
const HOST = ''
const KIBANA_ENDPOINT = '${HOST}/elasticsearch/_msearch?rest_total_hits_as_int=true&ignore_throttled=true'
const preamble = `{"index":"*","ignore_unavailable":true,"preference":1561797618673}`
const payload = {
version: true,
size: 100,
sort: [{
'@timestamp': {
order: "desc",
unmapped_type: "boolean"
}
}],
'_source': {
excludes: []
},
aggs: {
2: {
date_histogram: {
field: "@timestamp",
interval: "3h",
time_zone: "America/New_York",
min_doc_count: 1
}
}
},
stored_fields: [
"*"
],
script_fields: {},
docvalue_fields: [
{
"field": "@timestamp",
"format": "date_time"
},
{
"field": "T",
"format": "date_time"
},
{
"field": "responseTimestamp",
"format": "date_time"
},
{
"field": "scheduled time",
"format": "date_time"
},
{
"field": "time",
"format": "date_time"
},
{
"field": "updated_at",
"format": "date_time"
},
{
"field": "url.accessDate",
"format": "date_time"
},
{
field: "url.createDate",
format: "date_time"
}
],
query: {
bool: {
must: [
{
query_string: {
query: 'UnhandledPromiseRejectionWarning',
analyze_wildcard: true,
default_field: '*'
}
},
{
range: {
'@timestamp': {
gte: 1559239131823,
lte: 1561831131823,
format: 'epoch_millis'
}
}
}
],
filter: [],
should: [],
must_not: []
}
},
highlight: {
pre_tags: [
'@kibana-highlighted-field@'
],
post_tags: [
'@/kibana-highlighted-field@'
],
fields: {
'*': {}
},
fragment_size: 2147483647
},
timeout: '30000ms'
}
;(async () => {
const body = `${preamble}\n${JSON.stringify(payload)}\n`
const resp = await fetch(KIBANA_ENDPOINT, {
method: 'POST',
headers: {
'kbn-version': '6.6.0',
'Authorization': `Basic ${AUTH_TOKEN}`,
'content-type': 'application/x-ndjson'
},
body: body
})
const json = await resp.json()
const { responses } = json
const [response] = responses
const { hits: { hits } } = response
const logs = hits.map(({ _source }) => _source.log)
console.log(hits)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment