如何在client.search中传递查询变量?

时间:2018-12-06 02:32:19

标签: elasticsearch

如何在client.search中传递查询变量?

myapp.factory('dataservice',['$ q','esFactory','$ location',函数($ q,elasticsearch,$ location){

        var client = elasticsearch({
            host: 'https://mywebsitelink.in'
        });
        var search = function (term, offset) {

               var deferred = $q.defer();
            var query = {
                match: {
                    "title": term,
                    "url": term,
                    "content": term
                },
                size: 10,
                from: (offset || 0) * 10,
            };
            client.search({
                **HOW TO PASS THE QUERY PARAMETER HERE FOR ELASTIC SEARCH** 
            })
            .then(function (result) {
                //console.log(result);
                var ii = 0, hits_in, hits_out = [];
                hits_in = (result.hits || {}).hits || [];
                for (; ii < hits_in.length; ii++) {
                    if (hits_in[ii]._source.content != null)
                        hits_out.push(hits_in[ii]._source);
                }
                deferred.resolve(hits_out);
            }, deferred.reject
            );
            return deferred.promise;
        };
        return {
            search: search
        };
    }]);

0 个答案:

没有答案