[[full-body-search]] == Full-Body Search
Search lite—a <search
API,((("request body search"))) so called because
most parameters are passed in the HTTP request body instead of in the query
string.
Request body search--henceforth known as search—not only handles the query itself, but also allows you to return highlighted snippets from your results, aggregate analytics across all results or subsets of results, and return did-you-mean suggestions, which will help guide your users to the best results quickly.
=== Empty Search
Let's start with the simplest form of ((("request body search", "empty search")))((("empty search")))the search
API, the empty search,
which returns all documents in all indices:
GET /_search
// SENSE: 054_Query_DSL/60_Empty_query.json
<1> This is an empty request body.
Just as with a query-string search, you can search on one, many, or _all
indices, and one, many, or all types:
GET /index_2014*/type1,type2/_search
And you can use the from
and size
parameters((("pagination")))((("size parameter")))((("from parameter"))) for pagination:
GET /_search { "from": 30, "size": 10
[[get_vs_post]] .A GET Request with a Body?
The HTTP libraries of certain languages (notably JavaScript) don't allow GET
requests to have a request body. ((("searching", "using GET and POST HTTP methods for search requests")))((("HTTP methods", "GET and POST, use for search requests")))((("GET method", "no body for GET requests"))) In fact, some users are suprised that GET
requests are ever allowed to have a body.
The truth is that http://tools.ietf.org/html/rfc7231#page-24[RFC 7231]—the
RFC that deals with HTTP semantics and content--does not define what should
happen to a GET
request with a body! As a result, some HTTP servers allow
it, and some--especially caching proxies--don't.
The authors of Elasticsearch prefer using GET
for a search request because
they feel that it describes the action--retrieving information--better
than the POST
verb. However, because GET
with a request body is not
universally supported, the search
API also((("POST method", "use for search requests"))) accepts POST
requests:
POST /_search { "from": 30, "size": 10
The same rule applies to any other GET
API that requires a request body.
We present aggregations in depth in <
Instead of the cryptic query-string approach, a request body search allows us to write queries by using the query domain-specific language, or query DSL. ((("searching", "request body search", startref ="ix_reqbodysearch")))