[−][src]Struct elastic_types::document::prelude::IndexDocumentMapping
A wrapper type for serialising user types.
Serialising Document
will produce the mapping for the given type,
suitable as the mapping for
Put Mapping
or Create Index.
Examples
To serialise a document mapping, you can use its mapping type as a generic parameter in IndexDocumentMapping<M>
.
For example, we can define an index type for the Create Index API that includes the mapping for MyType
:
#[derive(Serialize, ElasticType)] pub struct MyType { pub my_date: Date<DefaultDateMapping>, pub my_string: String, pub my_num: i32 } #[derive(Default, Serialize)] pub struct MyIndex { pub mappings: Mappings } #[derive(Default, Serialize)] pub struct Mappings { pub mytype: IndexDocumentMapping<MyTypeMapping> }
Serialising MyIndex
will produce the following json:
{ "mappings": { "mytype": { "properties": { "my_date": { "type": "date", "format": "basic_date_time" }, "my_string": { "type": "text", "fields": { "keyword":{ "type":"keyword", "ignore_above":256 } } }, "my_num": { "type": "integer" } } } } }
Alternatively, you can implement serialisation manually for MyIndex
and avoid having
to keep field names up to date if the document type name changes:
#[derive(Serialize, ElasticType)] #[derive(Default, Serialize)] pub struct MyIndex { mappings: Mappings } #[derive(Default)] struct Mappings; impl Serialize for Mappings { fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { let mut state = serializer.serialize_struct("mappings", 1)?; state.serialize_field(MyType::static_ty(), &MyType::index_mapping())?; state.end() } }
Trait Implementations
impl<TMapping> Default for IndexDocumentMapping<TMapping> where
TMapping: ObjectMapping,
[src]
TMapping: ObjectMapping,
impl<TMapping> Serialize for IndexDocumentMapping<TMapping> where
TMapping: ObjectMapping,
[src]
TMapping: ObjectMapping,
Auto Trait Implementations
impl<TMapping> Send for IndexDocumentMapping<TMapping> where
TMapping: Send,
TMapping: Send,
impl<TMapping> Sync for IndexDocumentMapping<TMapping> where
TMapping: Sync,
TMapping: Sync,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Same for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,