# Time Based queries

**URL:** <https://discuss.elastic.co/t/time-based-queries/4989>\
**Category:** Elasticsearch\
**Created:** [July 28, 2011, 7:45pm UTC](https://discuss.elastic.co/t/time-based-queries/4989 "2011-07-28T19:45:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticUser](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@ElasticUser](https://discuss.elastic.co/u/ElasticUser)\
**Post date:** [July 28, 2011, 7:45pm UTC](https://discuss.elastic.co/t/time-based-queries/4989/1 "2011-07-28T19:45:30Z")

</div>

Hi,  
I am new to Elastic Search and currently looking into Java API. I have  
used XCOntentQueryBuilder  
XContentQueryBuilder qb = termQuery("@message", someString);

In addition to the name value pair , I also need to have time  
parameter passed to the query. Any suggestions on which QueryBuilder  
can be used? Any comments/suggestions welcome!

---

<div class="post-metadata">

**Author:** ![ElasticUser](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@ElasticUser](https://discuss.elastic.co/u/ElasticUser)\
**Post date:** [July 28, 2011, 10:11pm UTC](https://discuss.elastic.co/t/time-based-queries/4989/2 "2011-07-28T22:11:53Z")

</div>

Any inputs on this? I need to construct a query with multiple name/  
value pairs.

On Jul 28, 12:45 pm, ElasticUser [lkodwa...@gmail.com](mailto:lkodwa...@gmail.com) wrote:

> Hi,  
> I am new to Elastic Search and currently looking into Java API. I have  
> used XCOntentQueryBuilder  
> XContentQueryBuilder qb = termQuery("@message", someString);
> 
> In addition to the name value pair , I also need to have time  
> parameter passed to the query. Any suggestions on which QueryBuilder  
> can be used? Any comments/suggestions welcome!

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 29, 2011, 6:33am UTC](https://discuss.elastic.co/t/time-based-queries/4989/3 "2011-07-29T06:33:04Z")

</div>

One option is to use the bool query to combine different queries:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html).

Another option is to use filtered query:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

the query you want to execute, and a filter (which can be simple ones,  
like term/range/..., or compound ones like and/or).

Why you would want to use filters compared to queries is explained here:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/).

On Fri, Jul 29, 2011 at 1:11 AM, ElasticUser [lkodwaney@gmail.com](mailto:lkodwaney@gmail.com) wrote:

> Any inputs on this? I need to construct a query with multiple name/  
> value pairs.
> 
> On Jul 28, 12:45 pm, ElasticUser [lkodwa...@gmail.com](mailto:lkodwa...@gmail.com) wrote:
> 
> > Hi,  
> > I am new to Elastic Search and currently looking into Java API. I have  
> > used XCOntentQueryBuilder  
> > XContentQueryBuilder qb = termQuery("@message", someString);
> > 
> > In addition to the name value pair , I also need to have time  
> > parameter passed to the query. Any suggestions on which QueryBuilder  
> > can be used? Any comments/suggestions welcome!

---

<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/time-based-queries/4989/4 "2017-07-06T03:58:54Z")

</div>


