@@ -26,29 +26,16 @@ namespace Tests.ClientConcepts.HighLevel.Mapping
26
26
* When you use attributes, you *must* also call `.AutoMap()` for the attributes to be applied.
27
27
* --
28
28
*
29
- * Here we define the same two types as before, but this time using attributes to define the mappings.
29
+ * Here we define an `Employee` type and use attributes to define the mappings.
30
30
*/
31
31
public class AttributeMapping
32
32
{
33
33
private IElasticClient client = TestClient . GetInMemoryClient ( c => c . DisableDirectStreaming ( ) ) ;
34
34
35
- [ ElasticsearchType ( Name = "company" ) ]
36
- public class Company
37
- {
38
- [ Keyword ( NullValue = "null" , Similarity = "BM25" ) ]
39
- public string Name { get ; set ; }
40
-
41
- [ Text ( Name = "office_hours" ) ]
42
- public TimeSpan ? HeadOfficeHours { get ; set ; }
43
-
44
- [ Object ( Store = false ) ]
45
- public List < Employee > Employees { get ; set ; }
46
- }
47
-
48
35
[ ElasticsearchType ( Name = "employee" ) ]
49
36
public class Employee
50
37
{
51
- [ Text ( Name = "first_name" ) ]
38
+ [ Text ( Name = "first_name" , Norms = false , Similarity = "LMDirichlet" ) ]
52
39
public string FirstName { get ; set ; }
53
40
54
41
[ Text ( Name = "last_name" ) ]
@@ -66,15 +53,29 @@ public class Employee
66
53
[ Nested ]
67
54
[ PropertyName ( "empl" ) ]
68
55
public List < Employee > Employees { get ; set ; }
56
+
57
+ [ Text ( Name = "office_hours" ) ]
58
+ public TimeSpan ? OfficeHours { get ; set ; }
59
+
60
+ [ Object ( Store = false ) ]
61
+ public List < Skill > Skills { get ; set ; }
69
62
}
70
63
64
+ public class Skill
65
+ {
66
+ [ Text ]
67
+ public string Name { get ; set ; }
68
+
69
+ [ Number ( NumberType . Byte , Name = "level" ) ]
70
+ public int Proficiency { get ; set ; }
71
+ }
72
+
71
73
/**Then we map the types by calling `.AutoMap()` */
72
74
[ U ]
73
75
public void UsingAutoMapWithAttributes ( )
74
76
{
75
77
var createIndexResponse = client . CreateIndex ( "myindex" , c => c
76
78
. Mappings ( ms => ms
77
- . Map < Company > ( m => m . AutoMap ( ) )
78
79
. Map < Employee > ( m => m . AutoMap ( ) )
79
80
)
80
81
) ;
@@ -86,61 +87,6 @@ public void UsingAutoMapWithAttributes()
86
87
{
87
88
mappings = new
88
89
{
89
- company = new
90
- {
91
- properties = new
92
- {
93
- employees = new
94
- {
95
- properties = new
96
- {
97
- birthday = new
98
- {
99
- format = "MMddyyyy" ,
100
- type = "date"
101
- } ,
102
- empl = new
103
- {
104
- properties = new { } ,
105
- type = "nested"
106
- } ,
107
- first_name = new
108
- {
109
- type = "text"
110
- } ,
111
- isManager = new
112
- {
113
- null_value = false ,
114
- store = true ,
115
- type = "boolean"
116
- } ,
117
- last_name = new
118
- {
119
- type = "text"
120
- } ,
121
- salary = new
122
- {
123
- coerce = true ,
124
- doc_values = false ,
125
- ignore_malformed = true ,
126
- type = "float"
127
- }
128
- } ,
129
- type = "object" ,
130
- store = false
131
- } ,
132
- name = new
133
- {
134
- null_value = "null" ,
135
- similarity = "BM25" ,
136
- type = "keyword"
137
- } ,
138
- office_hours = new
139
- {
140
- type = "text"
141
- }
142
- }
143
- } ,
144
90
employee = new
145
91
{
146
92
properties = new
@@ -157,7 +103,9 @@ public void UsingAutoMapWithAttributes()
157
103
} ,
158
104
first_name = new
159
105
{
160
- type = "text"
106
+ type = "text" ,
107
+ norms = false ,
108
+ similarity = "LMDirichlet"
161
109
} ,
162
110
isManager = new
163
111
{
@@ -169,12 +117,32 @@ public void UsingAutoMapWithAttributes()
169
117
{
170
118
type = "text"
171
119
} ,
120
+ office_hours = new
121
+ {
122
+ type = "text"
123
+ } ,
172
124
salary = new
173
125
{
174
126
coerce = true ,
175
127
doc_values = false ,
176
128
ignore_malformed = true ,
177
129
type = "float"
130
+ } ,
131
+ skills = new
132
+ {
133
+ properties = new
134
+ {
135
+ level = new
136
+ {
137
+ type = "byte"
138
+ } ,
139
+ name = new
140
+ {
141
+ type = "text"
142
+ }
143
+ } ,
144
+ type = "object" ,
145
+ store = false
178
146
}
179
147
}
180
148
}
0 commit comments