I want to know the way to send a query in JSON format to ES from Java via a REST API. For example one of my query is given below the signature line. I want to construct an end point in my Java client like this: http://:9200//indexType> -q {"from":0,"size":1000,"query":{"bool":{"must":[..]...and so on..}
I have no problem with my Java. I just don't know the valid way of sending a JSON query to ES.
I want to avoid using org.elasticsearch.client.Client or org.elasticsearch.client.transport.TransportClient.
You can refer Elastic Java Rest for reference.
OR
You can also create a simple Rest Client using Java. Refer Rest Client using Java for code. To fetch data from elasticsearch you would need to make a POST Request to your respective elasctic index. Inclued your JSON query in the request body. e.g. your URL for HTTP Post request would be: http://yourhostname:9200/yourindextoquery/_search and the body would contain the query to execute.
RestClient kept having some issues, probably it was still my problems but I became impatient with it. However, Jersey REST client worked well. The key was in having the keyword _search in the end point and wrapping the query in the Entity class. Here's the code snippet:
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.