# Are there drawbacks to using .setQuery method to construct ElasticSearch Query?

**URL:** <https://discuss.elastic.co/t/are-there-drawbacks-to-using-setquery-method-to-construct-elasticsearch-query/54300>\
**Category:** Elasticsearch\
**Created:** [June 29, 2016, 3:03pm UTC](https://discuss.elastic.co/t/are-there-drawbacks-to-using-setquery-method-to-construct-elasticsearch-query/54300 "2016-06-29T15:03:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dadepo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadepo/32/19944_2.png) [@dadepo](https://discuss.elastic.co/u/dadepo)\
**Post date:** [June 29, 2016, 3:03pm UTC](https://discuss.elastic.co/t/are-there-drawbacks-to-using-setquery-method-to-construct-elasticsearch-query/54300/1 "2016-06-29T15:03:40Z")

</div>

I see that the `SearchRequestBuilder` has a `setQuery` method which allows querying by providing the query json string. Question is, is there any drawback to this approach compared with say using `QueryBuilder/FilterBuilder` which provides a different API to express the intended query?

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [June 29, 2016, 7:34pm UTC](https://discuss.elastic.co/t/are-there-drawbacks-to-using-setquery-method-to-construct-elasticsearch-query/54300/2 "2016-06-29T19:34:04Z")

</div>

No, there are no differences except that the `QueryBuilder/FilterBuilder`might do some initial input checking and its less likely to get errors because of wrong json syntax. In ES 2.x and earlier, the queries are sent to the nodes that execute the query in json (or an equivallent binary format) anyway. With the new upcoming version 5 this will change, there the `setQuery` method will only accept a QueryBuilder because the internal query serialization has changed, so if you want to plan for the future the builders are better.

---

<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:** [July 5, 2017, 10:39pm UTC](https://discuss.elastic.co/t/are-there-drawbacks-to-using-setquery-method-to-construct-elasticsearch-query/54300/3 "2017-07-05T22:39:30Z")

</div>


