Executing a standard search
In the previous recipe, we saw how to build queries. In this recipe, we can execute this query to retrieve some documents.
Getting ready
You need a working ElasticSearch cluster and a working copy of Maven.
The code of this recipe is in chapter_10/nativeclient in the code bundle of this book available on Packt's website and the referred class is QueryExample
.
How to do it...
For executing a standard query, we will perform the steps given as follows:
- After having created a query, to execute it is enough using the prepareQuery call and pass to it your query object. Here, there is a complete example:
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.SearchHit; import static org.elasticsearch.index.query.FilterBuilders.*; import static org.elasticsearch.index.query.QueryBuilders.*; public class QueryExample { public static void main(String...