js-data-elasticsearch

An elasticsearch adapter for the JSData Node.js ORM.

Usage no npm install needed!

<script type="module">
  import jsDataElasticsearch from 'https://cdn.skypack.dev/js-data-elasticsearch';
</script>

README

js-data logo

Codetree

npm Scrutinizer Build Scrutinizer Scrutinizer Coverage npm

js-data-elasticsearch

An elasticsearch adapter for the JSData Node.js ORM.

Installation

npm install --save js-data js-data-elasticsearch 

Usage

var jsDataElastic = require('js-data-elasticsearch');

/*
 *  Create an instance of ElasticSearchAdapter
 */
var adapter = new jsDataElastic({config: {
    host: 'localhost:9200',
    log: 'trace'
}});

/*
 *  Register the adapter instance
 */
store.registerAdapter('elasticsearch', adapter, { default: true });

JSData Tutorial

Start with the [JSData].

License

[The MIT License (MIT)]

Example

var jsData        = require('js-data');
var jsDataElastic = require('js-data-elasticsearch');

/*
 *  Optional
 */
jsData.utils.Promise = require('bluebird');

var config = {
  config: {
    host: 'localhost:9200',
    log: 'trace'
  }
};

var adapter = new jsDataElastic(config);

var container = new jsData.Container({ mapperDefaults: { } });

container.registerAdapter('elasticsearch', adapter, { 'default': true });

container.defineMapper('users');

container
    .count('users')
    .then(function (data) {
        res.send(JSON.stringify(data));
    })
    .catch(function (error) {
        res.send('ERROR<br>' + JSON.stringify(error));
    });

container
    .create('users',{name: 'name', password: 'password'})
    .then(function (data) {
        res.send(JSON.stringify(data));
    })
    .catch(function (error) {
        res.send('ERROR<br>' + JSON.stringify(error));
    });


container
    .findAll('users',{where: { password: { '==': 'password'} } })
    .then(function (data) {
        res.send(JSON.stringify(data));
    })
    .catch(function (error) {
        res.send('ERROR<br>' + JSON.stringify(error));
    });