pub struct Search { /* private fields */ }Expand description
A whole search request.
Implementations§
Source§impl Search
impl Search
Sourcepub fn new() -> Search
pub fn new() -> Search
Every document, ten at a time — what the cluster does with an empty body.
Sourcepub fn query_only(query: impl Into<Query>) -> Search
pub fn query_only(query: impl Into<Query>) -> Search
Start from a query, for the common case where nothing else is set.
pub fn query(self, query: impl Into<Query>) -> Search
Sourcepub fn from(self, from: u64) -> Search
pub fn from(self, from: u64) -> Search
How many hits to skip.
from + size may not exceed 10,000 without raising
index.max_result_window, and paging deep with it gets slower on every
page because every shard has to sort everything up to the offset.
search_after is the answer past a few pages; this is right for the
first few.
Sourcepub fn size(self, size: u64) -> Search
pub fn size(self, size: u64) -> Search
How many hits to return. Ten if not set.
Zero is legitimate and useful: an aggregation-only request pays for no hits at all.
pub fn sort_by(self, field: impl Into<String>, order: Order) -> Search
pub fn sort_asc(self, field: impl Into<String>) -> Search
pub fn sort_desc(self, field: impl Into<String>) -> Search
Sourcepub fn sort_by_score(self) -> Search
pub fn sort_by_score(self) -> Search
Sort by relevance, best first — the default when nothing is sorted.
Worth naming because adding any other sort silently replaces scoring
rather than tie-breaking on it, so a sorted search is no longer ranked
unless _score is put back in the list explicitly.
Sourcepub fn source<S: Into<String>>(
self,
fields: impl IntoIterator<Item = S>,
) -> Search
pub fn source<S: Into<String>>( self, fields: impl IntoIterator<Item = S>, ) -> Search
Return only these fields of the document.
Sourcepub fn source_excluding<S: Into<String>>(
self,
fields: impl IntoIterator<Item = S>,
) -> Search
pub fn source_excluding<S: Into<String>>( self, fields: impl IntoIterator<Item = S>, ) -> Search
Return everything except these fields.
Sourcepub fn without_source(self) -> Search
pub fn without_source(self) -> Search
Return the ids and scores but no document bodies.
pub fn aggregate( self, name: impl Into<String>, aggregation: impl Into<Aggregation>, ) -> Search
Sourcepub fn track_total_hits(self, exact: bool) -> Search
pub fn track_total_hits(self, exact: bool) -> Search
Count every match rather than stopping at 10,000.
This is the one setting behind crate::TotalHits being a relation and
not a number. Since Elasticsearch 7 the total stops being counted once
it passes index.max_result_window, and the response then says “at
least 10000” — which a caller that reads only value will render as
“10000 results” on a page listing millions. Turning this on makes the
number exact and makes the query slower; that trade is the caller’s to
make, so it is never made here.
Sourcepub fn track_total_hits_up_to(self, limit: u64) -> Search
pub fn track_total_hits_up_to(self, limit: u64) -> Search
Count exactly up to a limit, then stop.
The middle ground: enough to say “more than 1,000” honestly without paying to count a million.
Sourcepub fn count_body(&self) -> Json
pub fn count_body(&self) -> Json
The body _count accepts, which is the query and nothing else.
_count answers 400 for size, from, sort and aggs, so sending
the search body would turn a perfectly good search into a failed count.