# Best way to use Java API to search over last month word of data

**URL:** https://discuss.elastic.co/t/best-way-to-use-java-api-to-search-over-last-month-word-of-data/37686
**Category:** Elasticsearch
**Created:** [December 21, 2015, 11:44am UTC](https://discuss.elastic.co/t/best-way-to-use-java-api-to-search-over-last-month-word-of-data/37686 "2015-12-21T11:44:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![DK\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dk_3/32/48003_2.png) [@DK\_3](https://discuss.elastic.co/u/DK_3)
#### Post date: [December 21, 2015, 11:44am UTC](https://discuss.elastic.co/t/best-way-to-use-java-api-to-search-over-last-month-word-of-data/37686/1 "2015-12-21T11:44:06Z")

</div>

What's the most efficient way to search over a month of data??

I notice I can't do a scan query with a data aggregation:  
`AggregationBuilder DATE_AGG = AggregationBuilders.dateHistogram("agg") .field("@timestamp") .interval(DateHistogramInterval.MONTH);`

My Query:  
`QueryBuilder MY_QUERY = QueryBuilders.boolQuery() .must(QueryBuilders.matchQuery("field1", "ABC")) .must(QueryBuilders.matchQuery("field2", "XYZ")) ;`

So what I want is the fastest way to filter out documents to a specific month and filter based on field1 AND field2 existing and matching specific Strings. I think I need a match all query with multiple field filters.

---

<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, 11:29pm UTC](https://discuss.elastic.co/t/best-way-to-use-java-api-to-search-over-last-month-word-of-data/37686/2 "2017-07-05T23:29:33Z")

</div>


