In this section, we will discuss how to use a Java client to query Elasticsearch. In Chapter 4, Indexing and Updating Your Data, we discussed different types of Java clients and how to use them in your application for indexing. In this section, we will discuss how to use the client to query Elasticsearch. Let's take a simple match query as shown here:
#Match Query POST chapter7/_search { "query": { "match": { "product_name": "iphone" } } }
All the queries available via the REST API are also made available via the transport client. To execute the query using the Java client, first set up the client as shown next:
TransportAddress node1 = new InetSocketTransportAddress(InetAddress.getByName(