Note that "non-nullable" in this case does not mean "truthy" or "defined", but rather that the field cannot strictly equal
null. That is,
undefined is still a valid value.
Use this plugin in conjunction with elasticsearch-required to enforce required, non-nullable fields.
To install elasticsearch-required
npm install elasticsearch npm install --production elasticsearch-non-nullable
This plugin augments
client.indices.putMapping() to allow for the specification of non-nullable 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 non-nullable.
The following example demonstrates putting the mapping and indexing:
var Client = require'elasticsearch'Client;require'elasticsearch-non-nullable';// create the clientvar client =// put the mapping with "non-nullable" propertyclientputMapping"index" : "test""type" : "tweet""body" :"tweet" :"properties" :"message" :"type" : "string""non-nullable" : truethen// the following with result in "null value" errorreturn clientindex"index" : "test""type" : "tweet""body" :"message" : null;;
To run the unit tests
putMapping()when multiple indices are specified