Module string

Source
Expand description

Implementation of the Elasticsearch keyword and text types.

Keyword fields are stored as a raw string of tokens, and aren’t analysed when querying. They’re useful for data that only has meaning when considered as a whole, like an id or single word.

Text fields are stored as a sequence of tokens, constructed based on the given analyzer. They’re useful for blobs of content that can be sliced in various ways, like prose.

As far as serialisation is concerned, keyword and text are equivalent.

§Examples

For defining your own string mapping, see:

Map with a default string (follows the semantics for legacy string mapping):

struct MyType {
    pub field: String
}

Map a keyword:

struct MyType {
    pub field: Keyword<DefaultKeywordMapping>
}

Map text:

struct MyType {
    pub field: Text<DefaultTextMapping>
}

Map a custom type as a keyword field. This is especially useful for simple enums:

#[derive(Serialize)]
#[serde(rename_all = "lowercase")]
enum MyKeywordField {
    VariantA,
    VariantB,
    VariantC,
}

impl KeywordFieldType<DefaultKeywordMapping> for MyKeywordField {}

Re-exports§

pub use self::keyword::Keyword;
pub use self::text::Text;

Modules§

keyword
Implementation of the Elasticsearch keyword type.
mapping
Common mapping for the Elasticsearch string types.
prelude
Includes all types for the string types.
text
Implementation of the Elasticsearch text type.