Elasticness
This is a simple elasticsearch client for node.js. It wraps the http requests to your elasticsearch server. Here's how you use it.
var ElasticClient = ;var elastic = host: 'http://localhost' port: 9200 index: 'elastic-staging' indexProperties: /* ElasticSearch index options. Stuff like mappings and analyzers */ ;
Docs
This module exports a constructor that has a couple of static methods defined on it as well. Please refer to the elasticsearch documentation for method options.
Static Methods
Client.createIndex
Explicitly create an index - really shouldn't be used ever because elastic search will automatically create new indexes when saving documents
@param {String} host Hostname
@param {Number} port Port of the host
@param {String} name Name of the index
@param {Object} options Options for the elasticsearch index
@param {Function} callback Obviously the callback(error)
Example:
var ElasticClient = ; ElasticClient
Client.deleteIndex
Remove an index
@param {String} host Hostname
@param {Number} port Port of the host
@param {String} name Name of the index
@param {Object} options Options for the elasticsearch index
@param {Function} callback Obviously the callback(error)
Example:
var ElasticClient = ; ElasticClient
Instance Methods
Client.prototype.ensureIndex
Ensure the index that this client is associated to has been created
@param {Object} options [Optional] Options for the elasticsearch index
@param {Function} callback [Optional] Obviously the callback(error)
Example:
var ElasticClient = ; var elastic = host: 'http://localhost' port: 9200 index: 'elastic-staging'; elastic;
Client.prototype.removeSelf
Removes the index that this client is associated to
@param {Object} options [Optional] Options for the removal
@param {Function} callback [Optional] Obviously the callback(error)
Example:
var ElasticClient = ; var elastic = host: 'http://localhost' port: 9200 index: 'elastic-staging'; elastic;
Client.prototype.save
Add or update a document making it searchable
If an ID is supplied, an update is made to that resource. Otherwise, a POST is made. Either way, it doesnt really matter. ES will generate an id for you if you did not supply one. Please refer to ES documentation for the response sent to the client.
Also,
PUT /{index}/{type}/{id}
/staging/products/123
See http://www.elasticsearch.org/guide/reference/api/index_/
for more details
@param {String} type elastic search document type
@param {Object} doc The document to add or update
@param {Function} callback Obviously the callback(error, result)
Example:
var ElasticClient = ; var elastic = host: 'http://localhost' port: 9200 index: 'elastic-staging'; var doc = id: 111111111111 name: 'Some Product' price: 3400; elastic;
Client.prototype.get
Get a single document from elasticsearch
@param {String} type Elasticsearch document type
@param {Number} id ID of document - obviously can be String as well
@param {Function} callback Obviously the callback(error, result)
Example:
var ElasticClient = ; var elastic = host: 'http://localhost' port: 9200 index: 'elastic-staging'; elastic;
Client.prototype.getMapping
Get the mapping for a type
@param {String} type Elasticsearch document type
@param {Function} callback Obviously the callback(error, result)
Example:
var ElasticClient = ; var elastic = host: 'http://localhost' port: 9200 index: 'elastic-staging'; myClient;
Client.prototype.analyze
Runs test input on an analyzer. Returns the tokens the analyzer will match
@param {String} analyzer The analyzer to be run
@param {String} text The test input
@param {Function} callback Obviously the callback(error, result)
Example:
var ElasticClient = ; var elastic = host: 'http://localhost' port: 9200 index: 'elastic-staging' indexProperties: settings: analysis: analyzer: my_custom_analyzer: type: 'custom' tokenizer: 'standard' filter: 'standard' 'lowercase' 'asciifolding' ; myClient;
Client.prototype.search
Perform a search on elasticserach For all properties for search, see: http://www.elasticsearch.org/guide/reference/api/search/
Most searches use the query object, which uses the query-dsl: http://www.elasticsearch.org/guide/reference/query-dsl/
{
query: { ... }
, sort: { ... }
, fields: { ... }
, ...
}
@param {String} type Optional elastic search doc type
@param {Object} query Elastic search query dsl object
@param {Function} callback Obviously the callback(error, results)
Example:
var ElasticClient = ; var elastic = host: 'http://localhost' port: 9200 index: 'elastic-staging'; var $query = query: match: name: dataproduct ; elastic;
Example:
If you're searching on multiple fields, you might try the multi_match
search property.
var $query = query: multi_match: query: databusiness fields: 'name' 'name.partial' 'businessName' 'businessName.partial' ;
Client.prototype.del
Remove an item from elasticsearch
@param {String} type Elasticsearch document type
@param {Number} id ID of document - obviously can be String as well
@param {Function} callback Obviously the callback(error, result)
Example:
var ElasticClient = ; var elastic = host: 'http://localhost' port: 9200 index: 'elastic-staging'; myClient;
Client.prototype.info
Get server info
@param {Function} callback Obviously the callback(error, result)
Example:
var ElasticClient = ; var elastic = host: 'http://localhost' port: 9200 index: 'elastic-staging'; myClient;