New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

elasticsearch-mappings

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elasticsearch-mappings - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

65

main.js

@@ -48,9 +48,27 @@ #!/usr/bin/env node

// ES part
const dropExisitingOrForce = (mappings, callback) => {
async.filter(mappings, (mapping, done) => {
client.indices.exists({index: mapping.index}, exists => {
client.indices.exists({index: mapping.index}, (err, exists) => {
if (err) {
done(err)
}
if (exists && force) {
spinner.warn(`${mapping.index} is going to be delete.`)
// spinner.warn(`${mapping.index} is going to be delete.`)
client.indices.delete({index: mapping.index}, (err, res) => {
if (err) {
done(err)
}
if (res.acknowledged) {
done(null, true)
} else {
done(new Error(`${mapping.index} delete rejected: ${res}`))
}
})
} else if (exists && !force) {
// spinner.warn(`${mapping.index} already exists. Use -f (force option) to force recreate.`)
done(null, false)
} else {
done(null, true)
}
done(null, !exists || force)
})

@@ -62,8 +80,19 @@ }, callback)

spinner.succeed('Gathered config files.')
async.map(mappings, (mapping, done) => {
client.indices.delete({index: mapping.index, ignore: [404]})
.then(
client.indices.create(mapping).then(() => done(null), err => done(err))
)
}, callback)
async.each(mappings, (mapping, done) => {
client.indices.create(mapping, (err, res) => {
if (err) {
done(err)
}
if (!res.acknowledged || !res.shards_acknowledged) {
done(new Error(`${mapping.index} creation unsuccessful: ${res}`))
} else {
done(null)
}
})
}, err => {
if (err) {
callback(err)
}
callback(null, mappings)
})
}

@@ -78,7 +107,12 @@

createIndices
], err => {
], (err, res) => {
if (err) {
spinner.fail(`:(`)
throw err
}
spinner.succeed('Done.')
if (res.length === 0) {
spinner.succeed(`No indices created. Use -f (force) option to force index recreation.`)
} else {
spinner.succeed(`Successfully created ${res.length} ${res.length === 1 ? 'index' : 'indices'}! ${res.map(m => m.index)}`)
}
})

@@ -89,3 +123,3 @@ })

.version('1.0.0')
.command('delete <index>')
.command('delete [index]')
.option('-h, --host [optional]', 'The host URL of ElasticSearch.', 'localhost:9200')

@@ -102,7 +136,10 @@ .action((index, options) => {

client.indices.delete({index: index, ignore: [404]}).then(res => {
client.indices.delete({index: (index || '_all')}, (err, res) => {
if (err) {
spinner.fail(`Error occured. ${err}`)
}
if (res.acknowledged) {
spinner.succeed('Index delete!')
} else {
spinner.fail('Deleting index failed.')
spinner.fail(`Deleting index failed. ${res}`)
}

@@ -109,0 +146,0 @@ spinner.stop()

{
"name": "elasticsearch-mappings",
"version": "1.0.3",
"version": "1.0.4",
"description": "Easy to use elasticsearch schema/mappings uploader writen in nodejs.",

@@ -5,0 +5,0 @@ "main": "main.js",

@@ -14,9 +14,12 @@ [![Build Status](https://travis-ci.org/maticzav/elasticsearch-mappings.svg?branch=master)](https://travis-ci.org/maticzav/elasticsearch-mappings)

elasticsearch-mappings create [path] [-h] [-f]
elasticsearch-mappings delete <index>
elasticsearch-mappings delete [index]
```
__Options:__
### Create:
- ``[path]``: optional path to a mappings file or directory (current directory will be used by default).
- ``[-h, --host]``: optional elasticsearch host parameter (default: localhost:9200)
- ``[-f, --force]``: force recreation of indices.
### Delete:
- ``[index]``: optional index name (all indices will be delete by default).

@@ -37,2 +40,5 @@ ## Files

Running `elasticsearch-mappings delete bar` will delete only one index, `bar`.
Running `elasticsearch-mappings delete` will delete all/both indexes, `bar` and `foo`.
## Contribution

@@ -43,2 +49,2 @@ - Fork the repo.

__If you find a bug, open an issue or create a PR.__
__If you find a bug, please open an issue or create a PR.__
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc