3

So far I haven't found any samples of HOW the elastic.js client api (https://github.com/fullscale/elastic.js) can be used for indexing documents. There are some clues here & there but nothing concrete yet.

  • http://docs.fullscale.co/elasticjs/ejs.Document.html
  • Document ( index, type, id ): Object used to create, replace, update, and delete documents
  • Document > doIndex(fnCallBack): Stores a document in the given index and type. If no id is set, one is created during indexing.
  • Document > source (doc): Sets the source document.

Can anyone provide a sample snippet of code to show how an document object can be instantiated and used to index data?

Thanks!

Update # 1 (Sun Apr 21st, 2013 on 12:58pm CDT)

https://gist.github.com/pulkitsinghal/5430444

pulkitsinghal
  • 3,855
  • 13
  • 45
  • 84

2 Answers2

2

Your gist is correct.

You create ejs.Document objects specifying the index, type, and optionally the id of the document you want indexed. If you don't specify an id, elasticsearch will generate one for you.

You set the source to the json object you want indexed then call the doIndex method specifying a callback if needed. The node example does not index docs, but the angular and jquery examples show a basic example and can easily be used with the node client.

https://github.com/fullscale/elastic.js/blob/master/examples/angular/js/controllers.js#L30

Also have a peek at the tests:

https://github.com/fullscale/elastic.js/blob/master/tests/index_test.js#L265

Matt Weber
  • 342
  • 2
  • 5
  • 1
    It was a year ago, I can't even find the documentation on ejs.Document on the FullScale website ... – Romain Apr 01 '14 at 09:00
2

elastic.js nowadays only implements the Query DSL, so it can't be used for this scenario anymore. See this commit.

Yousef
  • 876
  • 6
  • 13