preference parameter allows
you to control which shards or nodes are
used to handle the search request. It accepts values such as
_shards:2,3, which are explained in detail on the
timeout parameter tells the coordinating node how long it should wait
before giving up and just returning the results that it already has. It can be
better to return some results than none at all.
The response to a search request will indicate whether the search timed out and how many shards responded successfully:
If all copies of a shard fail for other reasons—perhaps because of a
hardware failure—this will also be reflected in the
_shards section of
In Routing a Document to a Shard, we explained how a custom
provided at index time to ensure that all related documents, such as the
documents belonging to a single user, are stored on a single shard. At search
time, instead of searching on all the shards of an index, you can specify
one or more
routing values to limit the search to just those shards:
This technique comes in handy when designing very large search systems, and we discuss it in detail in Designing for Scale.
countsearch type has only a
queryphase. It can be used when you don’t need search results, just a document count or aggregations on documents matching the query.
query_and_fetchsearch type combines the query and fetch phases into a single step. This is an internal optimization that is used when a search request targets a single shard only, such as when a
routingvalue has been specified. While you can choose to use this search type manually, it is almost never useful to do so.
dfssearch types have a prequery phase that fetches the term frequencies from all involved shards in order to calculate global term frequencies. We discuss this further in Relevance Is Broken!.
scansearch type is used in conjunction with the
scrollAPI to retrieve large numbers of results efficiently. It does this by disabling sorting. We discuss scan-and-scroll in the next section.