如何在node,expressjs中弹性搜索中从mongoose创建索引 [英] how to create the index from mongoose in elastic search in node,expressjs

查看:151
本文介绍了如何在node,expressjs中弹性搜索中从mongoose创建索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用mongoose,express进行弹性搜索创建索引,但是没有可用的文档。我尝试mongoosastic,但这不舒服。

I want to create the index in elastic search with mongoose, express but there is no documentation available. I try mongoosastic but that is not comfortable.

那么有人可以帮助我吗?

So can anybody help me?

推荐答案

您可以使用此模块

https://github.com/elastic/elasticsearch-js

它使用起来非常简单并且有大量文档。

It's pretty simple to use and have a lot of documentation.

只需连接到DB->获取您需要的记录 - >为每个记录运行发布(client.bulk方法)。

Just connect to DB-> get records that you need-> for each record run publish(client.bulk method).

< a href =https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html\"rel =nofollow> https://www.elastic.co/ guide / en / elasticsearch / client / javascript-api / current / api-reference.html

编辑
以下是示例

EDIT Here is the example

var es = require('elasticsearch');
var client = new es.Client({
host:'localhost:9200',
log:'error'
});
// doc是mongoDB mocument
var bulkData = [{index:{_ index:yourIndexName,_ type:Any type,_ id:doc._id}},doc];
client.bulk({
requestTimeout:300000,
body:bulkData
},function(err,response){//此处最终回调});

希望这会有所帮助。

这篇关于如何在node,expressjs中弹性搜索中从mongoose创建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆