We have configured ES with the Couchbase cluster and were able to retrieve documents using some simple ES queries. Now let's discuss the steps involved in querying ES using Java APIs.
Here, I am not showing all of the code, as it will become repetitive. You can download the full source code from the website. I am going to show the code relevant to ES and how to retrieve the resultset.
In this process of querying ES and fetching documents, there are two steps. First, we need to connect to ElasticSearch and search the keywords using the REST API. This will return a resultset in a JSON document, as follows:
String url="http://localhost:9200/learningcouchbase/_search?pretty=true&q=skills:Couchbase+name:Henry"; static String fetchESQuery(String url) throws Exception { HttpGet request = new HttpGet(url); HttpClient client = HttpClientBuilder.create().build(); HttpResponse response = client.execute(request); BufferedReader rd = new BufferedReader(new...