简体   繁体   English

如何使用elastic.js客户端索引文档?

[英]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. 到目前为止,我还没有找到任何样本如何使用elastic.js客户端api( https://github.com/fullscale/elastic.js )来索引文档。 There are some clues here & there but nothing concrete yet. 这里和那里有一些线索,但没有具体的。

  • http://docs.fullscale.co/elasticjs/ejs.Document.html http://docs.fullscale.co/elasticjs/ejs.Document.html
  • Document ( index, type, id ): Object used to create, replace, update, and delete documents Document(index,type,id):用于创建,替换,更新和删除文档的对象
  • Document > doIndex(fnCallBack): Stores a document in the given index and type. Document> doIndex(fnCallBack):在给定的索引和类型中存储文档。 If no id is set, one is created during indexing. 如果未设置id,则在索引期间创建一个id。
  • Document > source (doc): Sets the source document. Document> source(doc):设置源文档。

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) 更新#1(2013年4月21日星期日下午12:58 CDT)

https://gist.github.com/pulkitsinghal/5430444 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. 您可以创建ejs.Document对象,指定要索引的文档的索引,类型和可选项。 If you don't specify an id, elasticsearch will generate one for you. 如果您没有指定id,elasticsearch将为您生成一个。

You set the source to the json object you want indexed then call the doIndex method specifying a callback if needed. 您将源设置为要索引的json对象,然后调用doIndex方法,指定回调(如果需要)。 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. 节点示例不索引文档,但angular和jquery示例显示了一个基本示例,可以轻松地与节点客户端一起使用。

https://github.com/fullscale/elastic.js/blob/master/examples/angular/js/controllers.js#L30 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 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. 现在,elastic.js只实现了Query DSL,所以它不能再用于这个场景了。 See this commit . 看到这个提交

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在elastic.js(elasticsearch)中计算具有相同值的字段? - How to count of fields with the same value in elastic.js (elasticsearch)? elastic.js + node.js:没有意义的查询 - elastic.js + node.js : queries not making sense 使用elastic.js查询与过滤器匹配的元素数量? - Query the number of elements matching a filter using elastic.js? TypeError:对象# <Object> 没有对Elastic.js使用方法&#39;Request&#39; - TypeError: Object #<Object> has no method 'Request' with elastic.js 如何将文档导入弹性搜索索引? - How to import documents into an elastic search index? 如何使用Node.js在Elasticsearch中索引1000多个文档? - How to index more than 1000 documents in Elasticsearch with Node.js? 弹性JS节点JS无法更新索引 - Elastic JS node JS unable to update index 如何在节点js控制器文件中引用弹性搜索JavaScript客户端库 - how to refer elastic search JavaScript client library in node js controller files 如何从部署在 AWS Elastic beanstalk 上的 node.js express 应用程序获取客户端 ip? - How to get client ip from node.js express application deployed on AWS Elastic beanstalk? 在将其传递给Node.js上的客户端之前,如何为mongodb中的文档字段分配一些值? - How to assign some values to fields of documents from mongodb before passing it to client on Node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM