Skip to main content

Search

Struct Search 

Source
pub struct Search { /* private fields */ }
Expand description

A whole search request.

Implementations§

Source

pub fn new() -> Search

Every document, ten at a time — what the cluster does with an empty body.

Source

pub fn query_only(query: impl Into<Query>) -> Search

Start from a query, for the common case where nothing else is set.

Source

pub fn query(self, query: impl Into<Query>) -> Search

Source

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.

Source

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.

Source

pub fn sort_by(self, field: impl Into<String>, order: Order) -> Search

Source

pub fn sort_asc(self, field: impl Into<String>) -> Search

Source

pub fn sort_desc(self, field: impl Into<String>) -> Search

Source

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.

Source

pub fn source<S: Into<String>>( self, fields: impl IntoIterator<Item = S>, ) -> Search

Return only these fields of the document.

Source

pub fn source_excluding<S: Into<String>>( self, fields: impl IntoIterator<Item = S>, ) -> Search

Return everything except these fields.

Source

pub fn without_source(self) -> Search

Return the ids and scores but no document bodies.

Source

pub fn aggregate( self, name: impl Into<String>, aggregation: impl Into<Aggregation>, ) -> Search

Source

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.

Source

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.

Source

pub fn min_score(self, score: f64) -> Search

Drop hits scoring below this.

Source

pub fn body(&self) -> Json

The JSON body this search sends.

Source

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.

Trait Implementations§

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.