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.
Use this plugin in conjunction with elasticsearch-non-nullable to enforce required, non-nullable fields.
To install elasticsearch-required
npm install elasticsearch npm install --production elasticsearch-required
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 clientvar client =// put the mapping with "required" propertyclientputMapping"index" : "test""type" : "tweet""body" :"tweet" :"properties" :"message" :"type" : "string""required" : truethen// the following with result in "missing required field" errorreturn clientindex"index" : "test""type" : "tweet""body" :;;
To run the unit tests
- Add support for bulk indexing
- Add support for
putMapping()when multiple indices are specified