# Building queries on the fly with java 1.7 api

**URL:** <https://discuss.elastic.co/t/building-queries-on-the-fly-with-java-1-7-api/35499>\
**Category:** Elasticsearch\
**Created:** [November 25, 2015, 12:09am UTC](https://discuss.elastic.co/t/building-queries-on-the-fly-with-java-1-7-api/35499 "2015-11-25T00:09:22Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [November 25, 2015, 10:40am UTC](https://discuss.elastic.co/t/building-queries-on-the-fly-with-java-1-7-api/35499/2 "2015-11-25T10:40:52Z")

</div>

Hi,

if you don't need scoring of your results, you basically want to combine two [AndFilters](https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.7/and-filter.html) containing [RangeFilter](https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.7/range-filter.html) and maybe a [TermFilter](https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.7/term-filter.html) for the string equality. The you put those into an [OrFilter](https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.7/or-filter.html). Or simply use two BoolFilters (about some of the differences see this [old topic](https://discuss.elastic.co/t/advice-needed-for-searching-filters-vrs-queries/11141/2)  
The building blocks should all be here: [https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.7/query-dsl-filters.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.7/query-dsl-filters.html)

Most filters can be created using FilterBuilders, the methods you use to set the parameters largely correpond to the Query DSL. That said, as soon as you switch to ES 2.0, there are going to be changes regarding the use of filters, since they are merged with queries. There's some general overview [here](https://www.elastic.co/blog/better-query-execution-coming-elasticsearch-2-0).

---

_[View the full topic](https://discuss.elastic.co/t/building-queries-on-the-fly-with-java-1-7-api/35499)._
