# QueryBuilderQuery

**URL:** <https://discuss.elastic.co/t/querybuilderquery/105538>\
**Category:** Elasticsearch\
**Created:** [October 27, 2017, 8:23am UTC](https://discuss.elastic.co/t/querybuilderquery/105538 "2017-10-27T08:23:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivekpandey564](https://avatars.discourse-cdn.com/v4/letter/v/858c86/32.png) [@vivekpandey564](https://discuss.elastic.co/u/vivekpandey564)\
**Post date:** [October 27, 2017, 8:23am UTC](https://discuss.elastic.co/t/querybuilderquery/105538/1 "2017-10-27T08:23:57Z")

</div>

if suppose i want to write query like

select \* from xyz where a="abc" and (createdDate between "?" and aprovedDate betwenn "?")

My intention is to write Query Builder query using this.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 27, 2017, 3:35pm UTC](https://discuss.elastic.co/t/querybuilderquery/105538/2 "2017-10-27T15:35:11Z")

</div>

you need a bool query, that contains three must clauses. One is a term query for the `a` field and the other two are range queries. you can use the `QueryBuilders` class to create those queries.

See [https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search.html)

---

<div class="post-metadata">

**Author:** ![vivekpandey564](https://avatars.discourse-cdn.com/v4/letter/v/858c86/32.png) [@vivekpandey564](https://discuss.elastic.co/u/vivekpandey564)\
**Post date:** [November 1, 2017, 7:13am UTC](https://discuss.elastic.co/t/querybuilderquery/105538/3 "2017-11-01T07:13:51Z")

</div>

a="abc " this condition always execute no matter what other condition is. Your solution is not creating proper query which is expected.

For eg:  
select \* from m\_country where approval\_status="SAVED" or (created\_date= "2017-12-30" or approved\_date ="2017-12-30")

Status result should be there other date related condition can be "AND" or "OR" no matter.

---

<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:** [November 29, 2017, 7:14am UTC](https://discuss.elastic.co/t/querybuilderquery/105538/4 "2017-11-29T07:14:16Z")

</div>

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