Last active
June 11, 2019 09:14
-
-
Save pracps/d92fe53c5f267718275819a033a6366b to your computer and use it in GitHub Desktop.
Elasticsearch sample nodejs search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Client } = require('@elastic/elasticsearch'); | |
const { URL } = require('url'); | |
let nodes = [{url: new URL("http://<server:port>")}, {url: new URL("<server:port>")},{url: new URL("<server:port>")}]; | |
const client = new Client({ | |
node: nodes, | |
maxRetries: 5, | |
requestTimeout: 60000, | |
sniffOnStart: true | |
}); | |
async function run () { | |
const { body } = await client.search({ | |
index: 'filebeat-7.1.1-2019.06.09-000001', | |
body: { | |
"sort": [{ | |
"@timestamp": { | |
"order": "asc" | |
}, | |
"log.offset": { | |
"order": "asc" | |
} | |
}], | |
"_source": ["message"], | |
query: { | |
match: { | |
"kubernetes.labels.job-name": "crf-cart-211-bcd8165-0-5" | |
} | |
}, | |
size: 10, | |
from: 10 | |
} | |
}); | |
console.dir(body.hits.hits); | |
} | |
run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Client } = require('@elastic/elasticsearch'); | |
const { URL } = require('url'); | |
let nodes = [{url: new URL("<es-server>")}, {url: new URL("<es-server>")},{url: new URL("<es-server>")}]; | |
const client = new Client({ | |
node: nodes, | |
maxRetries: 5, | |
requestTimeout: 60000, | |
sniffOnStart: true | |
}); | |
async function run () { | |
const { body } = await client.search({ | |
index: 'filebeat-7.1.1-2019.06.09-000001', | |
body: { | |
"sort": [{ | |
"@timestamp": { | |
"order": "asc" | |
}, | |
"log.offset": { | |
"order": "asc" | |
} | |
}], | |
"_source": ["message"], | |
query: { | |
match: { | |
"kubernetes.labels.job-name": "crf-cart-211-bcd8165-0-5" | |
} | |
}, | |
size: 10, | |
from: 10 | |
} | |
}); | |
console.dir(body.hits.hits); | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment