# How do I pass the query variable in client.search?

**URL:** <https://discuss.elastic.co/t/how-do-i-pass-the-query-variable-in-client-search/159644>\
**Category:** Elasticsearch\
**Created:** [December 6, 2018, 3:09am UTC](https://discuss.elastic.co/t/how-do-i-pass-the-query-variable-in-client-search/159644 "2018-12-06T03:09:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantgovekar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hemantgovekar/32/38493_2.png) [@hemantgovekar](https://discuss.elastic.co/u/hemantgovekar)\
**Post date:** [December 6, 2018, 3:09am UTC](https://discuss.elastic.co/t/how-do-i-pass-the-query-variable-in-client-search/159644/1 "2018-12-06T03:09:46Z")

</div>

myapp.factory('dataervice',  
['$q', 'esFactory', '$location', function ($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 QERY 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
        };
    }]);
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 3, 2019, 3:09am UTC](https://discuss.elastic.co/t/how-do-i-pass-the-query-variable-in-client-search/159644/2 "2019-01-03T03:09:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
