Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在节点expressjs的弹性搜索中从mongoose创建索引_Javascript_Node.js_Mongodb_Express_Mongoose - Fatal编程技术网

Javascript 如何在节点expressjs的弹性搜索中从mongoose创建索引

Javascript 如何在节点expressjs的弹性搜索中从mongoose创建索引,javascript,node.js,mongodb,express,mongoose,Javascript,Node.js,Mongodb,Express,Mongoose,我想用mongoose express在弹性搜索中创建索引,但没有可用的文档。我试过Mongoostic,但那不舒服 有人能帮我吗?你可以使用这个模块 它的使用非常简单,并且有很多文档 只需为每次记录运行发布(client.bulk方法)连接到DB->获取所需记录->即可 编辑 这是一个例子 var es=require('elasticsearch'); var client=新的es.client({ 主机:“localhost:9200”, 日志:“错误” }); //doc是mong

我想用mongoose express在弹性搜索中创建索引,但没有可用的文档。我试过Mongoostic,但那不舒服


有人能帮我吗?

你可以使用这个模块

它的使用非常简单,并且有很多文档

只需为每次记录运行发布(client.bulk方法)连接到DB->获取所需记录->即可

编辑 这是一个例子

var es=require('elasticsearch');
var client=新的es.client({
主机:“localhost:9200”,
日志:“错误”
});
//doc是mongoDB的文档
var-bulkData=[{index:{u-index:“yourIndexName”,_-type:“任意类型”,_-id:doc._-id}},doc];
客户机批量({
请求超时:300000,
正文:海量数据
},函数(err,response){//final callback here});


希望这有帮助。

您可以使用此模块

它的使用非常简单,并且有很多文档

只需为每次记录运行发布(client.bulk方法)连接到DB->获取所需记录->即可

编辑 这是一个例子

var es=require('elasticsearch');
var client=新的es.client({
主机:“localhost:9200”,
日志:“错误”
});
//doc是mongoDB的文档
var-bulkData=[{index:{u-index:“yourIndexName”,_-type:“任意类型”,_-id:doc._-id}},doc];
客户机批量({
请求超时:300000,
正文:海量数据
},函数(err,response){//final callback here});


希望这能有所帮助。

这对于索引来说效果很好。因此我添加了搜索查询。我的搜索查询如下所示

 esClient.search({
            'index': 'product',
            //'q': '*'+searchKeyword+'*' this is searching query
            'body': {
                'query': {
                    'prefix': {'_all': searchKeyword}
                }
            }
        },function(err, response){ 
})
var searchParams = {
  index: 'product',
  body: {
      query:{
      "fuzzy" : {
    "ProductName" : {
        "value" :         searchKeyword,
        "boost" :         1.0,
        "fuzziness" :     3,
        "prefix_length" : 0,
        "max_expansions": 100
    }
}
  }
    }
    }
但有一个问题。它只搜索基于文本的搜索,没有拼写错误,自动更正,附近,类似等。我想搜索查询谁是检查拼写错误,类似,附近的所有结果。所以请帮助我。
谢谢。

这对于索引来说效果很好。因此我添加了搜索查询。我的搜索查询如下所示

 esClient.search({
            'index': 'product',
            //'q': '*'+searchKeyword+'*' this is searching query
            'body': {
                'query': {
                    'prefix': {'_all': searchKeyword}
                }
            }
        },function(err, response){ 
})
var searchParams = {
  index: 'product',
  body: {
      query:{
      "fuzzy" : {
    "ProductName" : {
        "value" :         searchKeyword,
        "boost" :         1.0,
        "fuzziness" :     3,
        "prefix_length" : 0,
        "max_expansions": 100
    }
}
  }
    }
    }
但有一个问题。它只搜索基于文本的搜索,没有拼写错误,自动更正,附近,类似等。我想搜索查询谁是检查拼写错误,类似,附近的所有结果。所以请帮助我。
谢谢。

我已经找到了一个拼写错误搜索和基于全文的近邻搜索的解决方案。首先,我将定义拼写错误单词的模糊搜索

 var searchParams = {
      index: 'product',
      body: {
      "query": {
        "query_string": {
//search keyword is string which is searched
          "query": searchKeyword+'~',

        }
      }
    }
    };
esClient.search(searchParams,function(err, response){
})
另一个搜索类似于此的内容………..

    "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
         }
      }
    }
如果您想要模糊结果,也可以尝试此操作

 esClient.search({
            'index': 'product',
            //'q': '*'+searchKeyword+'*' this is searching query
            'body': {
                'query': {
                    'prefix': {'_all': searchKeyword}
                }
            }
        },function(err, response){ 
})
var searchParams = {
  index: 'product',
  body: {
      query:{
      "fuzzy" : {
    "ProductName" : {
        "value" :         searchKeyword,
        "boost" :         1.0,
        "fuzziness" :     3,
        "prefix_length" : 0,
        "max_expansions": 100
    }
}
  }
    }
    }

我已经找到了一个解决拼写错误搜索和全文搜索的方法。首先,我将定义拼写错误单词的模糊搜索

 var searchParams = {
      index: 'product',
      body: {
      "query": {
        "query_string": {
//search keyword is string which is searched
          "query": searchKeyword+'~',

        }
      }
    }
    };
esClient.search(searchParams,function(err, response){
})
另一个搜索类似于此的内容………..

    "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
         }
      }
    }
如果您想要模糊结果,也可以尝试此操作

 esClient.search({
            'index': 'product',
            //'q': '*'+searchKeyword+'*' this is searching query
            'body': {
                'query': {
                    'prefix': {'_all': searchKeyword}
                }
            }
        },function(err, response){ 
})
var searchParams = {
  index: 'product',
  body: {
      query:{
      "fuzzy" : {
    "ProductName" : {
        "value" :         searchKeyword,
        "boost" :         1.0,
        "fuzziness" :     3,
        "prefix_length" : 0,
        "max_expansions": 100
    }
}
  }
    }
    }

谢谢。我明白了。但是我有一个问题:client.bulk({body:[//操作描述{index:{{u index:'myindex',{u type:'mytype',{u id:1}},//要索引的文档{title:'foo},实际上我不知道如何在这个批量操作中添加我的db schema字段。你能给我看一些例子吗。谢谢谢谢。我明白了。但是我有一个问题:client.bulk({body:[//action description{index:{{u index:'myindex',{u type:'mytype',{u id:1}},//索引的文档{title:'foo'},实际上我不明白如何在这个批量操作中添加我的db架构字段。你能给我举个例子吗。谢谢