How to use the es function in es

To help you get started, we’ve selected a few es examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brozeph / reindeer / src / mapper.js View on Github external
function initialize (self, callback) {
	let
		client,
		cloneConfig = validators.clone(self._options);

	// due to behavior of `es` module, _type must not be specified to determine
	// if _index exists or not
	cloneConfig._type = undefined;
	client = elasticsearch(cloneConfig);

	return client.indices.exists((err, info) => {
		if (err) {
			return callback(err);
		}

		let data = {};

		// detect when index does not exist
		if (!info.exists) {
			// create the _type with supplied mapping while creating the _index
			data.mappings = {};
			data.mappings[self._options._type] =
				prepareMappingForElasticsearch(self._mapping);

			return client.indices.createIndex(data, (err) => {
github brozeph / reindeer / src / mapper.js View on Github external
constructor (options, mapping) {
		super();

		if (!options._index || typeof options._index !== 'string') {
			throw new Error('_index must be provided');
		}

		if (!options._type || typeof options._type !== 'string') {
			throw new Error('_type must be provided');
		}

		// initialize Mapper properties
		this._client = elasticsearch(options);
		this._dynamic = {};
		this._fields = {};
		this._fieldValidators = {};
		this._idPath = null;
		this._isInitialized = false;
		this._options = options;
		this._mapping = mapping;
		this._required = {};

		// analyze the input
		return analyze(this);
	}