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>
impl<T: Document, Tr: Transport> Index<T, Tr>
Sourcepub fn new(client: Client<Tr>, name: impl Into<String>) -> Index<T, Tr>
pub fn new(client: Client<Tr>, name: impl Into<String>) -> Index<T, Tr>
An index of documents of type T, by name.
Sourcepub fn refresh(self, refresh: Refresh) -> Index<T, Tr>
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.
Sourcepub async fn ensure_mapping(&self) -> Result<MappingReport, Error>
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.
Sourcepub async fn delete_index(&self) -> Result<(), Error>
pub async fn delete_index(&self) -> Result<(), Error>
Deletes the index, and every document in it.
Sourcepub async fn put(&self, document: &T) -> Result<Written, Error>
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.
Sourcepub async fn put_versioned(
&self,
document: &Versioned<T>,
) -> Result<Written, Error>
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.
Sourcepub async fn get(&self, id: &str) -> Result<Option<Versioned<T>>, Error>
pub async fn get(&self, id: &str) -> Result<Option<Versioned<T>>, Error>
A document by id, or None if there’s none.
Sourcepub async fn get_many<I: Into<String>>(
&self,
ids: impl IntoIterator<Item = I>,
) -> Result<Vec<Option<Versioned<T>>>, Error>
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.
Sourcepub async fn delete(&self, id: &str) -> Result<bool, Error>
pub async fn delete(&self, id: &str) -> Result<bool, Error>
Deletes a document by id; false if there was none.
Sourcepub async fn search(
&self,
retriever: impl Into<RetrieverContainer>,
) -> Result<Vec<Hit<T>>, Error>
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")).
Sourcepub async fn search_request(
&self,
body: RequestBody,
) -> Result<Response<T>, Error>
pub async fn search_request( &self, body: RequestBody, ) -> Result<Response<T>, Error>
Any search of the index, with documents read as T.
Source§impl<T: Document, Tr: Transport> Index<T, Tr>
impl<T: Document, Tr: Transport> Index<T, Tr>
Sourcepub fn esql(&self) -> Esql
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?;