@@ -5,18 +5,26 @@ pub mod prelude {
5
5
//!
6
6
//! This is a convenience module to make it easy to build mappings for multiple types without too many `use` statements.
7
7
8
- pub use super :: { ElasticType , ElasticMapping , NullMapping , IndexAnalysis , ElasticMappingVisitor } ;
8
+ pub use super :: { ElasticDataType , ElasticMapping , NullMapping , IndexAnalysis , ElasticMappingVisitor } ;
9
9
pub use :: date:: mapping:: * ;
10
10
pub use :: string:: mapping:: * ;
11
11
}
12
12
13
13
use std:: marker:: PhantomData ;
14
14
use serde;
15
15
16
- /// The base requirements for mapping an Elasticsearch type.
16
+ /// The base representation of an Elasticsearch data type.
17
17
///
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 {
20
28
/// The serialisation visitor used to inspect this mapping.
21
29
type Visitor : serde:: ser:: MapVisitor + Default ;
22
30
@@ -31,43 +39,42 @@ pub trait ElasticMapping<F = ()> {
31
39
}
32
40
33
41
/// Get the type name for this mapping, like `date` or `string`.
34
- fn field_type ( ) -> & ' static str {
42
+ fn data_type ( ) -> & ' static str {
35
43
""
36
44
}
37
45
}
38
46
39
47
/// 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 ) ]
41
49
pub struct NullMapping ;
42
50
impl ElasticMapping for NullMapping {
43
51
type Visitor = NullMappingVisitor ;
52
+
53
+ fn data_type ( ) -> & ' static str {
54
+ "object"
55
+ }
44
56
}
45
57
46
58
impl 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 >
48
60
where S : serde:: Serializer {
49
- Ok ( ( ) )
61
+ serializer . serialize_struct ( "mapping" , NullMappingVisitor :: default ( ) )
50
62
}
51
63
}
52
64
53
65
/// A default empty visitor.
54
66
#[ derive( Default , Debug , PartialEq ) ]
55
67
pub struct NullMappingVisitor ;
56
68
impl 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 >
58
70
where S : serde:: Serializer {
71
+ try!( serializer. serialize_struct_elt ( "type" , NullMapping :: data_type ( ) ) ) ;
72
+
59
73
Ok ( None )
60
74
}
61
75
}
62
76
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 .. { }
71
78
72
79
/// Should the field be searchable? Accepts `not_analyzed` (default) and `no`.
73
80
#[ derive( Debug , Clone , Copy ) ]
0 commit comments