Skip to main content

Query

Struct Query 

Source
pub struct Query(/* private fields */);
Expand description

One query clause.

Holds the JSON it will send, which is what makes Query::raw free and keeps this from becoming a second, worse copy of the DSL’s type system.

Implementations§

Source§

impl Query

Source

pub fn match_all() -> Query

Every document. What Elasticsearch assumes when no query is given.

Source

pub fn match_none() -> Query

No document. Useful for an aggregation-only request, where the hits are paid for and thrown away.

Source

pub fn matching(field: impl Into<String>, text: impl Into<String>) -> Match

Full-text search on one analysed field.

Returns a builder rather than a Query so the options that apply only to match — above all Match::and — are reachable. It converts wherever a Query is wanted.

Source

pub fn match_phrase(field: impl Into<String>, text: impl Into<String>) -> Match

The words in order and adjacent, rather than merely all present.

Source

pub fn multi_match<S: Into<String>>( text: impl Into<String>, fields: impl IntoIterator<Item = S>, ) -> Query

Full-text search across several fields at once.

A field may carry a weight — "title^3" — which is the ordinary way to say a match in the title counts for more than one in the body.

Source

pub fn term(field: impl Into<String>, value: impl Into<Json>) -> Query

An exact value, not analysed.

term compares against what is stored, so a text field almost never matches one: "Hello World" is indexed as hello and world, and a term query for Hello World finds nothing while reporting no error at all. Use this on keyword, numeric, boolean and date fields, and Query::matching on text.

Source

pub fn terms<V: Into<Json>>( field: impl Into<String>, values: impl IntoIterator<Item = V>, ) -> Query

Any one of several exact values — an IN list.

Source

pub fn exists(field: impl Into<String>) -> Query

Documents where the field has any value at all.

The negation is BoolQuery::must_not around this, which is also the only way to ask for “field is null”: Elasticsearch does not index a null, so there is nothing to match on directly.

Source

pub fn prefix(field: impl Into<String>, value: impl Into<String>) -> Query

A value starting with this prefix, against the stored term.

Source

pub fn wildcard(field: impl Into<String>, pattern: impl Into<String>) -> Query

A stored term matching a pattern, where * is any run and ? is one character. Expensive on a large index, and a leading * especially so.

Source

pub fn ids<S: Into<String>>(ids: impl IntoIterator<Item = S>) -> Query

Documents by _id.

Source

pub fn range(field: impl Into<String>) -> Range

A bounded field: Query::range("age").gte(18).lt(65).

Source

pub fn bool() -> BoolQuery

Combine clauses. See BoolQuery for what each slot means.

Source

pub fn all_of<Q: Into<Query>>(clauses: impl IntoIterator<Item = Q>) -> BoolQuery

Every clause must match, and each contributes to the score.

Source

pub fn any_of<Q: Into<Query>>(clauses: impl IntoIterator<Item = Q>) -> BoolQuery

At least one clause must match.

Sets minimum_should_match to 1, which is the difference between “any of these” and “prefer these”: a bare should beside a must is only a scoring hint, and a should list that nobody constrained happily matches documents satisfying none of it.

Source

pub fn raw(json: Json) -> Query

A clause this module does not name, written out as JSON.

Source

pub fn json(&self) -> &Json

Source

pub fn into_json(self) -> Json

Trait Implementations§

Source§

impl Clone for Query

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§

impl Debug for Query

Source§

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

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

impl From<BoolQuery> for Query

Source§

fn from(value: BoolQuery) -> Query

Converts to this type from the input type.
Source§

impl From<Match> for Query

Source§

fn from(value: Match) -> Query

Converts to this type from the input type.
Source§

impl From<Range> for Query

Source§

fn from(value: Range) -> Query

Converts to this type from the input type.
Source§

impl PartialEq for Query

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
Source§

impl StructuralPartialEq for Query

Auto Trait Implementations§

§

impl Freeze for Query

§

impl RefUnwindSafe for Query

§

impl Send for Query

§

impl Sync for Query

§

impl Unpin for Query

§

impl UnsafeUnpin for Query

§

impl UnwindSafe for Query

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.