Executing a standard search
In the previous recipe, we saw how to build a query. In this recipe we can execute this query to retrieve some documents.
Getting ready
You will 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 placed on Packt's website, and on GitHub (https://github.com/aparo/elasticsearch-cookbook-second-edition). The referred class is QueryExample
.
How to do it...
To execute a standard query, we will perform the following steps:
- After having created a query, it is enough to use the
prepareQuery
call in order to execute it and pass it your query object. Here is a complete example:import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; ...
Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.