Skip to content

Commit

Permalink
added support for specifying multiple matchType
Browse files Browse the repository at this point in the history
  • Loading branch information
ferronrsmith committed Nov 9, 2023
1 parent 765d1e5 commit 268576d
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions bin/multielasticdump
Original file line number Diff line number Diff line change
Expand Up @@ -340,34 +340,47 @@ if (options.direction === 'dump') {
path: '/_aliases'
}

if (options.matchType === 'datastream') {
req.path = '/_data_stream'
const pathEnum = {
alias: '/_aliases',
datastream: '/_data_stream'
}

elasticRequest(req, (response) => {
switch (options.matchType) {
case 'alias': {
let indexes = response
if (!Array.isArray(response)) {
indexes = Object.keys(response)
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}`))
}

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
}
matchedIndexes = indexes.filter(index => {
const aliases = Object.keys(response[index].aliases || {})
return matchRegExp.test(index) || aliases.some(alias => matchRegExp.test(alias))
})
break
}
case 'datastream': {
matchedIndexes = response.data_streams.filter(stream => matchRegExp.test(stream.name)).map(stream => stream.name)
break
}
default:
args.log('err', new Error(`invalid matchType ${options.matchType}`))
process.exit(1)
}

matchedIndexes = _.orderBy(matchedIndexes, _.identity, [options.order])
// matchedIndices = _.orderBy(matchedIndices, _.identity, [options.order])

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 268576d

Please sign in to comment.