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

elasticsearch-required

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elasticsearch-required

A plugin for the Elasticsearch JavaScript client that enforces required fields when indexing

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Introduction

Elasticsearch does not come with built-in support for specifying certain fields as required. This plugin module adds this capability to the Elasticsearch JavaScript client by checking the data before it is indexed.

Note that "required" in this case does not mean "truthy", but rather that the field is specified. That is, null is still a valid value.

Usage

Installation

To install elasticsearch-required

npm install elasticsearch
npm install --production elasticsearch-required

Usage

This plugin augments client.indices.putMapping() to allow for the specification of required fields. As such, it is required that you call putMapping on every instance of the Elasticsearch client before indexing so that the plugin can be initialized with what fields are required.

The following example demonstrates putting the mapping and indexing:

var Client = require('elasticsearch').Client;
require('elasticsearch-required');

// create the client
var client = ...

// put the mapping with "required" property
client.putMapping({
	"index" : "test",
	"type" : "tweet",
	"body" : {
		"tweet" : {
			"properties" : {
				"message" : {
					"type" : "string",
					"required" : true
				}
			}
		}
	}
}).then(function () {
	// the following with result in "missing required field" error
	return client.index({
		"index" : "test",
		"type" : "tweet",
		"body" : {
		}
	});
});

Testing

To run the unit tests

npm test

TODO

  • Add support for bulk indexing
  • Add support for putMapping() when multiple indices are specified

License

MIT

FAQs

Package last updated on 14 May 2014

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