# Using Java API to create a query

**URL:** <https://discuss.elastic.co/t/using-java-api-to-create-a-query/5029>\
**Category:** Elasticsearch\
**Created:** [August 2, 2011, 12:16pm UTC](https://discuss.elastic.co/t/using-java-api-to-create-a-query/5029 "2011-08-02T12:16:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![spokarna](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@spokarna](https://discuss.elastic.co/u/spokarna)\
**Post date:** [August 2, 2011, 12:16pm UTC](https://discuss.elastic.co/t/using-java-api-to-create-a-query/5029/1 "2011-08-02T12:16:00Z")

</div>

Hi All,

I am attempting to write a parser that will help me to translate a simple query language into ElasticSearch objects.

I am not how to do this for a query like  
source=file && ip=127.0.0.1 AND (timestamp between xxx and yyy)

I want to pass the object to the search method. What are the builder objects that I should be using?

For a simple expression  
source=file AND (timestamp between xxx and yyy)  
I can do this:  
qb = QueryBuilders.filteredQuery  
(termQuery(key, value),  
rangeFilter("timestamp").from(this.getStartTime()).to(this.getEndTime()));

Thanks and regards,  
Sameer

---

<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 6, 2017, 3:58am UTC](https://discuss.elastic.co/t/using-java-api-to-create-a-query/5029/2 "2017-07-06T03:58:30Z")

</div>


