Node.js Elasticsearch Mongoosastic 来自和分页大小

Node.js Elasticsearch Mongoosastic From and Size For Pagination

我正在使用 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);
    }
);