简体   繁体   English

Node.js Elasticsearch分页的大小和大小

[英]Node.js Elasticsearch Mongoosastic From and Size For Pagination

I am using Mongoosastic for indexing my model to Elasticsearch , its work very well and only problem i have its on From and Size for pagination . 我正在使用Mongoosastic将我的模型索引到Elasticsearch,它的工作非常好,唯一的问题是我在From和Size上可以进行分页。

according to Mongoosastic api it 根据Mongoosastic API,

full query DSL of Elasticsearch is exposed through the search method 通过搜索方法公开Elasticsearch的完整查询DSL

Based on Elasticsearch Api From/Size i come to this code 基于Elasticsearch Api From / Size我来到了这段代码

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

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

and after runnig i come up with this error : 在runnig之后,我想出了这个错误:

/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)

Any thoughts? 有什么想法吗? Thanks in advance! 提前致谢!

Mongoosastic has following signature of search function: Mongoosastic具有以下搜索功能签名:

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

It has 3 arguments, where second is options. 它有3个参数,第二个是选项。 Hence, your code should looks like this: 因此,您的代码应如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM