Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add .gitifnore and some documentations

  • Loading branch information...
commit 1a1cd855163896117d7b56eeb6432909149f955f 1 parent 2341b3e
@pedrosnk authored
Showing with 73 additions and 6 deletions.
  1. +1 −0  .gitignore
  2. +69 −6 lib/elastico.js
  3. +3 −0  package.json
View
1  .gitignore
@@ -0,0 +1 @@
+node_modules
View
75 lib/elastico.js
@@ -1,10 +1,20 @@
-/*
- * Elastico is a library created to make connections with the elastic search
- */
+// Elastico.js 0.0.1
+// -----------------
+// Elastico may be distrubited under MIT license
+
+// Requores http dependecy to make request to elasticsearch
var http = require('http');
+// Declaration of Class Elastic Search
Elastico = function(){
+ // This are the custom options that
+ // can be used to configure the connection with
+ // the elasticsearch client.
+ //
+ // var client = new Elastico();
+ // client.options.host = 'my_elastic_search_ip';
+ //
this.options = {
host: 'localhost'
,port: 9200
@@ -14,6 +24,14 @@ Elastico = function(){
Elastico.prototype = {
+ // Function used to generate get an index from the
+ // elasticsearch client it will return the raw json from the
+ // elasticsearch.
+ //
+ // client.getIndex('my_index','my_type', 'my_key', function(data){
+ // console.log(data);
+ // });
+ //
getIndex: function (index, type, key, callback){
var req = http.request(this.options.protocol + "://" + this.options.host + ":" +
this.options.port + "/" + index + "/" + type + "/" + key, function(res) {
@@ -30,6 +48,21 @@ Elastico.prototype = {
req.end();
},
+ // Used to get all the data from an expecific index and type
+ // returning the raw json from elastic search it is possible
+ // to pass some options at the body of the request. sse more
+ // at [elasticsearch docs](http://www.elasticsearch.org/guide)
+ //
+ // client.getAll('my_index', 'my_type', function(data){
+ // console.log(data);
+ // });
+ //
+ // with options
+ //
+ // client.getAll('my_index', 'my_type', function(data){
+ // console.log(data);
+ // }, {size: 30} );
+ //
getAll: function (index, type, callback, extras){
var body = JSON.stringify(extras);
var options = {
@@ -60,9 +93,21 @@ Elastico.prototype = {
req.end();
},
- /*
- * TODO: return the id of the object
- */
+ // Responsable to insert some object data into the
+ // elasticsearch client. the data must be passad as
+ // string. recommended to use JSON.stringfy(value)
+ // it will let elasticsearch to auto generate an id for
+ // the object
+ //
+ // var obj = {foo: "bar" };
+ // client.insert('my_index','my_type',JSON.strinfy(obj), function(success) {
+ // if (success === true){
+ // console.log('success')
+ // } else {}
+ // console.log('some error occoured');
+ // }
+ // });
+ //
insert: function (index, type, value, callback) {
var options = {
host: this.options.host,
@@ -86,6 +131,19 @@ Elastico.prototype = {
req.end();
},
+ // Does the same job as the insert function, but
+ // it is possible to pass an id predetermined to the elasticsearch
+ // it is useful in case you need to overwrite a data into elasticsearch
+ //
+ // var obj = {foo: "bar" };
+ // client.insertWithId('my_index','my_type','my_id',JSON.strinfy(obj), function(success) {
+ // if (success === true){
+ // console.log('success')
+ // } else {}
+ // console.log('some error occoured');
+ // }
+ // });
+ //
insertWithId: function (index, type, id, value, callback) {
var options = {
host: this.options.host,
@@ -110,6 +168,11 @@ Elastico.prototype = {
req.end();
},
+ // Useful to remove some data by passing it id into elasticsearch
+ //
+ // client.remove('my_index','my_type','my_id', function(success) {
+ // console.log("removed? - " + success);
+ // });
remove: function(index, type, id, callback) {
var options = {
host: this.options.host,
View
3  package.json
@@ -7,6 +7,9 @@
"devDependencies": {
"mocha": "1.3.2"
,"should": "1.1.0"
+ ,"pygments": "0.1.3"
+ ,"coffee-script": "1.3.3"
+ ,"docco": "0.4.0"
},
"repository": {
"type": "git",
Please sign in to comment.
Something went wrong with that request. Please try again.