Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonapi-store-elasticsearch

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonapi-store-elasticsearch

Elasticsearch data store for jsonapi-server.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Coverage Status Build Status npm version Code Climate Dependencies Status

jsonapi-store-elasticsearch

jsonapi-server-elasticsearch is a Elasticsearch backed data store for jsonapi-server.

This project conforms to the specification laid out in the jsonapi-server handler documentation.

Usage

var ElasticsearchStore = require("jsonapi-store-elasticsearch");

jsonApi.define({
  resource: "comments",
  handlers: new ElasticsearchStore({
    host: "localhost:9200"
  })
});

Features

  • Search, Find, Create, Delete, Update
  • Filtering, Sorting, Pagination

Getting to Production

Getting this data store to production isn't too bad...

  1. Bring up your Elasticsearch stack.
  2. Create an index, give it a sensible name.
  3. Create an alias for your index to the name "jsonapi".
  4. Create the mapping for your resource. If you rely on the automatic mapping, you won't be able to sort on any attributes, and thus pagination won't work either.
  5. Deploy your code.
  6. Celebrate.

You'll probably want to override this handler's search functionality in order to achieve high-performance queries. That may look something like this:

var efficientHandler = new ElasticsearchStore({
  host: "localhost:9200"
});
// the next function correlates with the jsonapi-server handler documentation:
// https://github.com/holidayextras/jsonapi-server/blob/master/documentation/handlers.md
efficientHandler.search = function(request, callback) {
  // within this scope, this._db is the Elasticsearch client
  var efficientQuery = buildAwesomeQuery();
  this._db.search(efficientQuery, callback);
};

jsonApi.define({
  resource: "comments",
  handlers: efficientHandler
});

When making schema changes...

If you are only adding new attributes, you can push in a mapping for the new attribute, deploy your code changes and celebrate.

If you are making destructive changes, you'll need to create a new index, add a fresh mapping, migrate data into it and finally swap the "jsonapi" alias to point to your new index. You can read this section on how to switch aliases around: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#indices-aliases

Keywords

FAQs

Package last updated on 06 Jan 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc