I've got a NodeJS app that uses @elastic/elasticstack
's client.
I'm trying to get a list of indexes (or indices) from my elastic database.
I'm new to elastic, but when this REST endpoint is called I get back 695 results and I believe I've only created a couple indexes.
The code calling elastic to find the indexes is:
const express = require('express')
const app = express()
const { Client } = require('@elastic/elasticsearch')
const clientOpts = {}; // connect info not shown
const client = new Client(clientOpts)
app.get('/es/indices', async (req, res) => {
let queryInfo = {
index: '_all'
};
client.indices.stats(queryInfo).then(result => {
console.log('/es/index got =', JSON.stringify(result.body, null,2));
res.send(result.body);
}).catch(ex => {
console.error('/es/index failed ', ex);
res.status(500).send({ error: { message: ex.message, stack: ex.stack } });
})
})
Below is a short snippet showing the results and one of my index.
"data": {
"_shards": {
"total": 695,
"successful": 695,
"failed": 0
},
"myindex": {
"uuid": "xuuoc19mTJyfvjZlyMZVxB",
"primaries": {
"docs": {
"count": 303375,
"deleted": 0
},
(Q) What's the way to get a list of the indexes that contain user data on an Elastic Database?
Searching for solution
Elastic docs
I found the Elastic documentation but it has very little useful information other than repeating the names of the parameters. For example, URL indices.stats
defines the function as:
client.indices.stats({
metric: string | string[],
index: string | string[],
completion_fields: string | string[],
fielddata_fields: string | string[],
fields: string | string[],
groups: string | string[],
level: 'cluster' | 'indices' | 'shards',
types: string | string[],
include_segment_file_sizes: boolean,
include_unloaded_segments: boolean,
expand_wildcards: 'open' | 'closed' | 'hidden' | 'none' | 'all',
forbid_closed_indices: boolean
})
But does little to explain what the parameter values mean/do.
metric
string | string[] - Limit the information returned the specific metrics.
I'm using ElasticSearch version 7.17 which is why the URL points to that version.
Similar SO Question
I found the SO Question/answer: https://stackoverflow.com/a/17429465/3281336
which I tried but the aliases
API returns way more than what I wanted.