簡體   English   中英

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

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

我正在使用Mongoosastic將我的模型索引到Elasticsearch,它的工作非常好,唯一的問題是我在From和Size上可以進行分頁。

根據Mongoosastic API,

通過搜索方法公開Elasticsearch的完整查詢DSL

基於Elasticsearch Api From / Size我來到了這段代碼

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

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

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

有什么想法嗎? 提前致謝!

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);
    }
);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM