# Developing a batch file to run elasticsearch query

**URL:** <https://discuss.elastic.co/t/developing-a-batch-file-to-run-elasticsearch-query/60256>\
**Category:** Elasticsearch\
**Created:** [September 12, 2016, 7:04am UTC](https://discuss.elastic.co/t/developing-a-batch-file-to-run-elasticsearch-query/60256 "2016-09-12T07:04:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Varun\_Breja](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@Varun\_Breja](https://discuss.elastic.co/u/Varun_Breja)\
**Post date:** [September 12, 2016, 7:04am UTC](https://discuss.elastic.co/t/developing-a-batch-file-to-run-elasticsearch-query/60256/1 "2016-09-12T07:04:32Z")

</div>

Hi Team,

I am a newcomer in ElasticSearch and trying to develop a batch file in Java. I have two parts of my question:

Part-1:

The functionality of this batch will be to run a query like the below:

POST /test/\_search?pretty  
{  
"query": {  
"match\_all": {  
}  
},  
"aggregations":{  
"top\_lastName":{  
"terms": {  
"field": "Last\_Name"  
}  
}  
}  
}

When I run this query from Sense it is working fine and giving the output in a JSON format. I just want to capture this JSON output  
in a JSON flat file by Core Java code. Please suggest some sample code and the kind of JARs (with its version) I need to have for the same.

Part 2:

Please let me know in case I try to capture only those records w.r.t SYSDATE-1 how will I form the query considering "DATE" type column is "Created\_Date".

Thanks in advance..

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 12, 2016, 7:43am UTC](https://discuss.elastic.co/t/developing-a-batch-file-to-run-elasticsearch-query/60256/2 "2016-09-12T07:43:18Z")

</div>

What is not working well in your batch file? It is hard to help if we don't know what errors you get.

---

<div class="post-metadata">

**Author:** ![Varun\_Breja](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@Varun\_Breja](https://discuss.elastic.co/u/Varun_Breja)\
**Post date:** [September 12, 2016, 7:44am UTC](https://discuss.elastic.co/t/developing-a-batch-file-to-run-elasticsearch-query/60256/3 "2016-09-12T07:44:49Z")

</div>

I have requested for a sample code if you have.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 12, 2016, 9:56am UTC](https://discuss.elastic.co/t/developing-a-batch-file-to-run-elasticsearch-query/60256/4 "2016-09-12T09:56:00Z")

</div>

You can start here: [https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html)

---

<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, 10:21pm UTC](https://discuss.elastic.co/t/developing-a-batch-file-to-run-elasticsearch-query/60256/5 "2017-07-05T22:21:11Z")

</div>


