pub struct Index { /* private fields */ }
Expand description
ElasticSearch client.
The client is stateless. It only contains a HTTP client, the index name and the config on how to connect to ElasticSearch.
We use elasticsearch-rs, you can find the documentation on docs.rs.
Implementations
sourceimpl Index
impl Index
sourcepub fn new(
client: Arc<Elasticsearch>,
name: impl ToString,
mapping: Value
) -> Self
pub fn new(
client: Arc<Elasticsearch>,
name: impl ToString,
mapping: Value
) -> Self
Create a new Index client from an Elasticsearch client and index name.
sourcepub async fn ensure_index(&self, delete: bool) -> Result<(), IndexError>
pub async fn ensure_index(&self, delete: bool) -> Result<(), IndexError>
Inititialize ElasticSearch.
This creates the elasticsearch index with the default index mapping if it does not exists. It should be called before calling other methods on the client.
sourcepub async fn put_typed_records<T: TypedValue>(
&self,
docs: &[Record<T>]
) -> Result<BulkPutResponse, IndexError>
pub async fn put_typed_records<T: TypedValue>(
&self,
docs: &[Record<T>]
) -> Result<BulkPutResponse, IndexError>
Put a list of Records to the index.
Internally the Records are transformed to UntypedRecords, serialized and saved in a single bulk operation.
sourcepub async fn put_untyped_records(
&self,
docs: &[UntypedRecord]
) -> Result<BulkPutResponse, IndexError>
pub async fn put_untyped_records(
&self,
docs: &[UntypedRecord]
) -> Result<BulkPutResponse, IndexError>
Put a list of UntypedRecords to the index
sourcepub async fn update_nested_record(
&self,
field: &str,
record: &UntypedRecord
) -> Result<(), Error>
pub async fn update_nested_record(
&self,
field: &str,
record: &UntypedRecord
) -> Result<(), Error>
Update all nested documents on a top-level field with the value from an UntypedRecord.
We have a relation from [Post] to Media Because of this data model we have a nested field on the elasticsearch level which we have to update as soon as the data arrives. This function will usually be called with update from a ChangesStream.
See this Article for details on working with nested documents in ElasticSearch.
pub async fn query_records<Q: Serialize + Debug>(
&self,
query: Q
) -> Result<Vec<UntypedRecord>, Error>
sourcepub async fn find_records_with_text_query(
&self,
query: &str
) -> Result<Vec<UntypedRecord>, Error>
pub async fn find_records_with_text_query(
&self,
query: &str
) -> Result<Vec<UntypedRecord>, Error>
Simple string query on the index.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Index
impl Send for Index
impl Sync for Index
impl Unpin for Index
impl !UnwindSafe for Index
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
self
into a collection.fn mapped<U, F, A>(self, f: F) -> SmallVec<A>where
F: FnMut(T) -> U,
A: Array<Item = U>,
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Self