- Java Transport Client (deprecated): other versions:
- Preface
- Maven Repository
- Client
- Index API
- Get API
- Delete API
- Bulk API
- Search API
- Count API
- Delete By Query API
- Facets
- Percolate API
- Query DSL - Queries
- Match Query
- MultiMatch Query
- Boolean Query
- Boosting Query
- IDs Query
- Constant Score Query
- Disjunction Max Query
- Fuzzy Like This (Field) Query (flt and flt_field)
- FuzzyQuery
- Has Child / Has Parent
- MatchAll Query
- More Like This (Field) Query (mlt and mlt_field)
- Prefix Query
- QueryString Query
- Range Query
- Span Queries (first, near, not, or, term)
- Term Query
- Terms Query
- Top Children Query
- Wildcard Query
- Nested Query
- Indices Query
- GeoShape Query
- Query DSL - Filters
- And Filter
- Bool Filter
- Exists Filter
- Ids Filter
- Limit Filter
- Type Filter
- Geo Bounding Box Filter
- GeoDistance Filter
- Geo Distance Range Filter
- Geo Polygon Filter
- Geo Shape Filter
- Has Child / Has Parent Filters
- Match All Filter
- Missing Filter
- Not Filter
- Or Filter
- Prefix Filter
- Query Filter
- Range Filter
- Script Filter
- Term Filter
- Terms Filter
- Nested Filter
- Caching
IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Search API
editSearch API
editThe search API allows one to execute a search query and get back search hits
that match the query. It can be executed across one or more indices and
across one or more types. The query can either be provided using the
query Java API or
the filter Java API.
The body of the search request is built using the
SearchSourceBuilder
. Here is an example:
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.index.query.FilterBuilders.*; import org.elasticsearch.index.query.QueryBuilders.*;
SearchResponse response = client.prepareSearch("index1", "index2") .setTypes("type1", "type2") .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setQuery(QueryBuilders.termQuery("multi", "test")) // Query .setPostFilter(FilterBuilders.rangeFilter("age").from(12).to(18)) // Filter .setFrom(0).setSize(60).setExplain(true) .execute() .actionGet();
Note that all parameters are optional. Here is the smallest search call you can write:
// MatchAll on the whole cluster with all default options SearchResponse response = client.prepareSearch().execute().actionGet();
For more information on the search operation, check out the REST search docs.
Was this helpful?
Thank you for your feedback.