Developing a batch file to run elasticsearch query

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..

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

I have requested for a sample code if you have.

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