简体   繁体   中英

How to index documents with elastic.js client?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM