alireza
alireza

Reputation: 557

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 .

according to Mongoosastic api it

full query DSL of Elasticsearch is exposed through the search method

Based on Elasticsearch Api From/Size i come to this code

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 :

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

Upvotes: 1

Views: 2252

Answers (1)

Igor Denisenko
Igor Denisenko

Reputation: 254

Mongoosastic has following signature of search function:

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

It has 3 arguments, where second is options. 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);
    }
);

Upvotes: 7

Related Questions