Skip to content

Commit

Permalink
added support for matchType (datastream|alias)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferronrsmith committed Nov 9, 2023
1 parent 7c4fb60 commit a497eeb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ The limited option set includes:

- `parallel`: `os.cpus()`,
- `match`: `'^.*$'`,
- `matchType`: `alias`,
- `order`: `'asc'`,
- `input`: `null`,
- `output`: `null`,
Expand Down Expand Up @@ -778,6 +779,8 @@ i.e analyzer,alias types are ignored by default

`--ignoreChildError` allows multi-elasticdump to continue if a child throws an error.

`--matchType` allows multi-elasticdump to fetch index name from elasticsearch alias endpoint of data_streams


New options, `--suffix` allows you to add a suffix to the index name being created e.g. `es6-${index}` and
`--prefix` allows you to add a prefix to the index name e.g. `${index}-backup-2018-03-13`.
Expand Down
46 changes: 37 additions & 9 deletions bin/multielasticdump
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const defaults = {
debug: true,
parallel: os.cpus().length,
match: '^.*$',
matchType: 'alias',
order: 'asc',
input: null,
output: null,
Expand Down Expand Up @@ -339,17 +340,44 @@ if (options.direction === 'dump') {
path: '/_aliases'
}

elasticRequest(req, (response) => {
let indexes = response
if (!Array.isArray(response)) {
indexes = Object.keys(response)
const pathEnum = {
alias: '/_aliases',
datastream: '/_data_stream'
}

async.map(_.chain(options.matchType).split(',').uniq().value(), (type, callback) => {
let matchedIndices = []
req.path = pathEnum[type]
if (req.path === undefined) {
return callback(new Error(`invalid matchType ${type}`))
}
matchedIndexes = indexes.filter(index => {
const aliases = Object.keys(response[index].aliases || {})
return matchRegExp.test(index) || aliases.some(alias => matchRegExp.test(alias))
})
matchedIndexes = _.orderBy(matchedIndexes, _.identity, [options.order])

elasticRequest(req, (response) => {
switch (type) {
case 'alias': {
let indexes = response
if (!Array.isArray(response)) {
indexes = Object.keys(response)
}
matchedIndices = indexes.filter(index => {
const aliases = Object.keys(response[index].aliases || {})
return matchRegExp.test(index) || aliases.some(alias => matchRegExp.test(alias))
})
break
}
case 'datastream': {
matchedIndices = response.data_streams.filter(stream => matchRegExp.test(stream.name)).map(stream => stream.name)
break
}
}
callback(null, matchedIndices)
})
}, (err, results) => {
if (err) {
args.log('err', err)
process.exit(1)
}
matchedIndexes = _.chain(results).flatten().orderBy(_.identity, [options.order]).value()
dumpWork()
})
}
Expand Down

0 comments on commit a497eeb

Please sign in to comment.