如何在节点中的弹性search中使用mongoose创build索引,expressjs

我想用mongoose在弹性search中创build索引,但是没有可用的文档。 我尝试mongoosastic,但不舒服。

那么有人能帮助我吗?

你可以使用这个模块

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

使用起来非常简单,并且有很多文档。

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

https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html

编辑这里是例子

var es = require('elasticsearch'); var client = new es.Client({ host: 'localhost:9200', log: 'error' }); //doc is the mongoDB mocument var bulkData = [{index: {_index: "yourIndexName", _type: "Any type", _id: doc._id}}, doc]; client.bulk({ requestTimeout: 300000, body: bulkData }, function(err, response){//final callback here});

希望这可以帮助。

这是工作正常indexing.so我已经添加searchquery.mysearch查询是这样的

  esClient.search({ 'index': 'product', //'q': '*'+searchKeyword+'*' this is searching query 'body': { 'query': { 'prefix': {'_all': searchKeyword} } } },function(err, response){ }) 

但有一个问题。只search基于文本的search没有拼写错误,自动更正,附近,类似等我想search查询谁被检查拼错,类似,附近的所有results.so plzz人帮我。 谢谢。

我已经find一个解决拼写错误的search和全文基于附近search。首先,我将定义模糊search拼写错误的单词。

  var searchParams = { index: 'product', body: { "query": { "query_string": { //search keyword is string which is searched "query": searchKeyword+'~', } } } }; esClient.search(searchParams,function(err, response){ }) 

另一个更像这样的search……………

  "more_like_this": { "fields": [ "productName","description","brand" ], //searchKeyword is a string variable for searching "like_text": searchKeyword, "min_term_freq": 1, "min_doc_freq": 1, "max_query_terms": 12 } } } 

如果你想模糊结果,那么也试试这个

 var searchParams = { index: 'product', body: { query:{ "fuzzy" : { "ProductName" : { "value" : searchKeyword, "boost" : 1.0, "fuzziness" : 3, "prefix_length" : 0, "max_expansions": 100 } } } } }