Skip to main content

Index

Struct Index 

Source
pub struct Index<T, Tr> { /* private fields */ }
Expand description

An index, or an alias, holding documents of type T.

Implementations§

Source§

impl<T: Document, Tr: Transport> Index<T, Tr>

Source

pub fn new(client: Client<Tr>, name: impl Into<String>) -> Index<T, Tr>

An index of documents of type T, by name.

Source

pub fn name(&self) -> &str

The index’s name.

Source

pub fn client(&self) -> &Client<Tr>

The client.

Source

pub fn refresh(self, refresh: Refresh) -> Index<T, Tr>

Writes refresh the index this way, to make them visible to searches sooner: Refresh::WaitFor waits for the next refresh. By default they don’t.

Source

pub async fn ensure_mapping(&self) -> Result<MappingReport, Error>

Makes the index’s mapping the document type’s: creates the index if it doesn’t exist, adds the fields it lacks, and reports fields mapped differently, which it never changes.

A new index for a type with vector fields keeps vectors in the _source it returns (index.mapping.exclude_source_vectors: false), so documents read back whole.

Source

pub async fn delete_index(&self) -> Result<(), Error>

Deletes the index, and every document in it.

Source

pub async fn put(&self, document: &T) -> Result<Written, Error>

Writes a document, with the id from its #[id] field, replacing any with the same id.

Source

pub async fn put_versioned( &self, document: &Versioned<T>, ) -> Result<Written, Error>

Writes a document back if it hasn’t changed since it was read, and fails with Error::Conflict if it has.

Source

pub async fn get(&self, id: &str) -> Result<Option<Versioned<T>>, Error>

A document by id, or None if there’s none.

Source

pub async fn get_many<I: Into<String>>( &self, ids: impl IntoIterator<Item = I>, ) -> Result<Vec<Option<Versioned<T>>>, Error>

Documents by id, in the same order, with None for each that doesn’t exist.

Source

pub async fn delete(&self, id: &str) -> Result<bool, Error>

Deletes a document by id; false if there was none.

Source

pub async fn search( &self, retriever: impl Into<RetrieverContainer>, ) -> Result<Vec<Hit<T>>, Error>

The best ten documents a retriever finds. A query is a retriever too: Retriever::standard(Article::TITLE.r#match("hnsw")).

Source

pub async fn search_request( &self, body: RequestBody, ) -> Result<Response<T>, Error>

Any search of the index, with documents read as T.

Source

pub async fn fuse(&self, fusion: &Fusion) -> Result<Fused<T>, Error>

Fuses retrievers’ results, on the server if its license allows, else on the client.

Source§

impl<T: Document, Tr: Transport> Index<T, Tr>

Source

pub fn esql(&self) -> Esql

An ES|QL query FROM the index, to build on and run with Esql::fetch, which reads the rows as the documents, or as any other type, by column name:

ⓘ
let popular: Vec<Note> = notes
    .esql()
    .where_(col("views").gte(100))
    .sort([col("views").desc()])
    .limit(10)
    .fetch(notes.client())
    .await?;

Trait Implementations§

Source§

impl<T, Tr: Clone> Clone for Index<T, Tr>

Source§

fn clone(&self) -> Index<T, Tr>

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<T, Tr> Debug for Index<T, Tr>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, Tr> Freeze for Index<T, Tr>
where Client<Tr>: Freeze, PhantomData<fn() -> T>: Freeze,

§

impl<T, Tr> RefUnwindSafe for Index<T, Tr>

§

impl<T, Tr> Send for Index<T, Tr>
where Client<Tr>: Send, PhantomData<fn() -> T>: Send,

§

impl<T, Tr> Sync for Index<T, Tr>
where Client<Tr>: Sync, PhantomData<fn() -> T>: Sync,

§

impl<T, Tr> Unpin for Index<T, Tr>
where Client<Tr>: Unpin, PhantomData<fn() -> T>: Unpin,

§

impl<T, Tr> UnsafeUnpin for Index<T, Tr>

§

impl<T, Tr> UnwindSafe for Index<T, Tr>
where Client<Tr>: UnwindSafe, PhantomData<fn() -> T>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more