gpt4 book ai didi

Node.js Elasticsearch Mongoosastic 分页的来源和大小

转载 作者:太空宇宙 更新时间:2023-11-03 22:42:36 29 4
gpt4 key购买 nike

我正在使用Mongoosastic为了将我的模型索引到 Elasticsearch,它工作得很好,唯一的问题是我在分页的 From 和 Size 上遇到了问题。

根据 Mongoosastic api

full query DSL of Elasticsearch is exposed through the search method

基于Elasticsearch Api From/Size我看到这段代码

music.search( {query_string:{ query:term }},{"from" : 0},{"size" : 10}, { hydrate:true }, function(err,results) { 

console.log(results.hits.hits);
})

运行后我遇到了这个错误:

/home/app/node_modules/mongoosastic/lib/mongoosastic.js:256
cb(null, res);
^
TypeError: object is not a function
at /home/app/node_modules/mongoosastic/lib/mongoosastic.js:256:9
at respond (/home/app/node_modules/mongoosastic/node_modules/elasticsearch/src/lib/transport.js:256:9)
at checkRespForFailure (/home/app/node_modules/mongoosastic/node_modules/elasticsearch/src/lib/transport.js:203:7)
at HttpConnector.<anonymous> (/home/app/node_modules/mongoosastic/node_modules/elasticsearch/src/lib/connectors/http.js:156:7)
at IncomingMessage.wrapper (/home/app/node_modules/lodash/index.js:3057:19)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:944:16
at process._tickCallback (node.js:448:13)

有什么想法吗?提前致谢!

最佳答案

Mongoosastic 具有以下搜索功能签名:

schema.statics.search = function(query, options, cb) {
// blah blah
}

它有 3 个参数,其中第二个是选项。因此,您的代码应如下所示:

music.search(
{
query_string: {
query: term
}
},
{
from: 0,
size: 10,
hydrate: true
},
function(err,results) {
console.log(results.hits.hits);
}
);

关于Node.js Elasticsearch Mongoosastic 分页的来源和大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30228784/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com