Struct elastic_types::document::IndexDocumentMapping []

pub struct IndexDocumentMapping<M> where
    M: DocumentMapping
{ /* fields omitted */ }

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 = try!(serializer.serialize_struct("mappings", 1));

        try!(state.serialize_field(MyType::name(), &IndexDocumentMapping::from(MyType::mapping())));

        state.end()
    }
}

Trait Implementations

impl<M> Serialize for IndexDocumentMapping<M> where
    M: DocumentMapping
[src]

Serialize this value into the given Serde serializer. Read more

impl<M: Default> Default for IndexDocumentMapping<M> where
    M: DocumentMapping
[src]

Returns the "default value" for a type. Read more

impl<M> From<M> for IndexDocumentMapping<M> where
    M: DocumentMapping
[src]

Performs the conversion.