@@ -5,18 +5,26 @@ pub mod prelude {
55 //!
66 //! This is a convenience module to make it easy to build mappings for multiple types without too many `use` statements.
77
8- pub use super :: { ElasticType , ElasticMapping , NullMapping , IndexAnalysis , ElasticMappingVisitor } ;
8+ pub use super :: { ElasticDataType , ElasticMapping , NullMapping , IndexAnalysis , ElasticMappingVisitor } ;
99 pub use :: date:: mapping:: * ;
1010 pub use :: string:: mapping:: * ;
1111}
1212
1313use std:: marker:: PhantomData ;
1414use serde;
1515
16- /// The base requirements for mapping an Elasticsearch type.
16+ /// The base representation of an Elasticsearch data type.
1717///
18- /// Each type will have its own implementing structures with extra type-specific mapping parameters.
19- pub trait ElasticMapping < F = ( ) > {
18+ /// # Links
19+ ///
20+ /// - [Elasticsearch docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html)
21+ pub trait ElasticDataType < T : ElasticMapping < F > , F > { }
22+
23+ /// The base requirements for mapping an Elasticsearch data type.
24+ ///
25+ /// Each type has its own implementing structures with extra type-specific mapping parameters.
26+ pub trait ElasticMapping < F = ( ) >
27+ where Self : Default + serde:: Serialize {
2028 /// The serialisation visitor used to inspect this mapping.
2129 type Visitor : serde:: ser:: MapVisitor + Default ;
2230
@@ -31,43 +39,42 @@ pub trait ElasticMapping<F = ()> {
3139 }
3240
3341 /// Get the type name for this mapping, like `date` or `string`.
34- fn field_type ( ) -> & ' static str {
42+ fn data_type ( ) -> & ' static str {
3543 ""
3644 }
3745}
3846
3947/// A mapping implementation for a non-core type, or any where nobody cares about how it's mapped.
40- #[ derive( Debug , PartialEq ) ]
48+ #[ derive( Debug , PartialEq , Default ) ]
4149pub struct NullMapping ;
4250impl ElasticMapping for NullMapping {
4351 type Visitor = NullMappingVisitor ;
52+
53+ fn data_type ( ) -> & ' static str {
54+ "object"
55+ }
4456}
4557
4658impl serde:: Serialize for NullMapping {
47- fn serialize < S > ( & self , _ : & mut S ) -> Result < ( ) , S :: Error >
59+ fn serialize < S > ( & self , serializer : & mut S ) -> Result < ( ) , S :: Error >
4860 where S : serde:: Serializer {
49- Ok ( ( ) )
61+ serializer . serialize_struct ( "mapping" , NullMappingVisitor :: default ( ) )
5062 }
5163}
5264
5365/// A default empty visitor.
5466#[ derive( Default , Debug , PartialEq ) ]
5567pub struct NullMappingVisitor ;
5668impl serde:: ser:: MapVisitor for NullMappingVisitor {
57- fn visit < S > ( & mut self , _ : & mut S ) -> Result < Option < ( ) > , S :: Error >
69+ fn visit < S > ( & mut self , serializer : & mut S ) -> Result < Option < ( ) > , S :: Error >
5870 where S : serde:: Serializer {
71+ try!( serializer. serialize_struct_elt ( "type" , NullMapping :: data_type ( ) ) ) ;
72+
5973 Ok ( None )
6074 }
6175}
6276
63- impl ElasticType < ( ) , NullMapping > for .. { }
64-
65- /// A type that can be indexed in Elasticsearch.
66- //TODO: Rename to ElasticDataType
67- pub trait ElasticType < T : ElasticMapping < F > , F > { }
68-
69- //TODO: Need ElasticType, which is a main type that can be derived
70- //This needs to map each property. Probably through a custom derive
77+ impl ElasticDataType < ( ) , NullMapping > for .. { }
7178
7279/// Should the field be searchable? Accepts `not_analyzed` (default) and `no`.
7380#[ derive( Debug , Clone , Copy ) ]
0 commit comments