Skip to content

Instantly share code, notes, and snippets.

@pracps
Last active June 11, 2019 09:14
Show Gist options
  • Save pracps/d92fe53c5f267718275819a033a6366b to your computer and use it in GitHub Desktop.
Save pracps/d92fe53c5f267718275819a033a6366b to your computer and use it in GitHub Desktop.
Elasticsearch sample nodejs search
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();
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