ES snippets in JavaScript (AWS)
const { Client } = require('@elastic/elasticsearch');
const client = new Client({
node: '<URL>',
auth: {
username: process.env.USERNAME,
password: process.env.PASSWORD
}
});
es.client.cat.indices({ format: 'json' }) .then(console.log);
await es.client.indices.delete({ index: 'INDEX_NAME' });
const count = (await es.client.count({
index: 'INDEX_NAME',
body: {
query: {
bool: {
filter: [
{ terms: { "COLUMN_NAME.keyword": ['..', '..'] } },
]
}
},
}
})).body.count;
const objects = (await es.client.search({
index: 'INDEX_NAME',
body: {
query: {
bool: {
filter: [
{ terms: { "COLUMN_NAME.keyword": ['..', '..'] } },
]
}
},
}
})).body.hits.hits;
const ids = objects.map(o => o._id);
const values = objects.map(o => o._source);