Socket
Socket
Sign inDemoInstall

@condor-labs/elasticsearch

Package Overview
Dependencies
26
Maintainers
5
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @condor-labs/elasticsearch

This module provide and usefull helper to use Elasticsearch library


Version published
Maintainers
5
Install size
1.57 MB
Created

Readme

Source

This module provide and usefull helper to use Elasticsearch library.

See official documentation here.

Compatibility

The minimum supported version of Node.js is v8.

The library is compatible with all Elasticsearch versions since 5.x

How to use it

To use the library you just need to follow the following steps Install the library with npm

npm install @condor-labs/elasticsearch

Import the library:

const elasticsearch = require('@condor-labs/elasticsearch')(settings);

settings object properties

PropertyDefaultDescription
protocol (String)httpSpecify http protocol
host (String)127.0.0.1The host name of the ES instance you are connecting to.
port (Number)9200The port number to connect to.
user (String)The username for authentication.
password (String)The password for authentication.

Examples

constants.js

module.exports = {
    settings: {
        protocol: 'http',
        user: '',
        password: '',
        host: 'localhost',
        port: 9200
    },
    indexBody: {
        index: 'game-of-thrones',
        type: 'characters',
        body: {
            character: 'Ned Stark',
            quote: 'Winter is coming.'
        }
    },
    searchBody: {
        size: 100,
        from: 0,
        body: {
            query: {
                match: {
                    character: 'Stark'
                }
            }
        }
    }
};

index.js

const {
    settings,
    indexBody,
    searchBody
} = require('./constants');

try {
    const es = require('@condor-labs/elasticsearch')(settings);
    (async () => {
        // get client
        let client = es.getClient();

        //---------------- 
        // Let's start by indexing some data
        //---------------- 
        let resp = await client.index(indexBody)
        // validate response
        console.log(resp && resp.statusCode === 201 ? "Saving document is OK!" : "Saving document didn't work :(");
        console.log('---------------------------------------');

        //---------------- 
        // search data just added:
        //---------------- 

        // promise API
        resp = await client.search(searchBody);

        console.log(resp && resp.body && resp.body.hits && resp.body.hits.total > 0 ? `${resp.body.hits.total} Docs found via Promise!!!` : `NO Docs found via promises :( `);
        console.log('---------------------------------------');

        resp = await client.search(
            searchBody,
            (err, resp) => {
                if (err) {
                    console.error(err)
                }
                console.log(resp && resp.body && resp.body.hits && resp.body.hits.total > 0 ? `${resp.body.hits.total} Docs found via CB!!!` : `NO Docs found via CB :( `);
                console.log('---------------------------------------');
                // close app
                process.exit(1);
            }
        );
    })();
} catch (error) {
    console.error(error)
}

How to Publish

Increasing package version

You will need to update the package.json file placed in the root folder.

identify the property version and increase the right number in plus one.

Login in NPM by console.

 npm login
 [Enter username]
 [Enter password]
 [Enter email]

If all is ok the console will show you something like this : Logged in as USERNAME on https://registry.npmjs.org/.

Uploading a new version

 npm publish --access public

Ref: https://docs.npmjs.com/getting-started/publishing-npm-packages

Note: you will need to have a NPM account, if you don't have one create one here: https://www.npmjs.com/signup

Contributors

The original author and current lead maintainer of this module is the @condor-labs development team.

More about Condorlabs Here.

License

MIT

Keywords

FAQs

Last updated on 14 Jan 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc