-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathFluentMappingFullExampleTests.cs
259 lines (252 loc) · 6.54 KB
/
FluentMappingFullExampleTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using NUnit.Framework;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Nest;
using Newtonsoft.Json.Converters;
using Nest.Resolvers.Converters;
using Nest.Tests.MockData.Domain;
namespace Nest.Tests.Unit.Core.Map
{
[TestFixture]
public class FluentMappingFullExampleTests : BaseJsonTests
{
[Test]
public void MapFluentFull()
{
//most of these merely specify the defaults and are superfluous
//No asserts just a global overview of what the fluent mapping is capable off.
var result = this._client.Map<ElasticsearchProject>(m => m
.Type("elasticsearchprojects2")
.Indices("nest_test_data", "nest_test_data_clone")
.IgnoreConflicts()
.IndexAnalyzer("standard")
.SearchAnalyzer("standard")
.DynamicDateFormats(new[] { "dateOptionalTime", "yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z" })
.DateDetection(true)
.NumericDetection(true)
//MapFromAttributes() is shortcut to fill property mapping using the types' attributes and properties
//Allows us to map the exceptions to the rule and be less verbose.
.MapFromAttributes()
.SetParent<Person>() //makes no sense but i needed a type :)
.AllField(a=>a
.Enabled()
.IndexAnalyzer("nGram_analyzer")
.SearchAnalyzer("whitespace_analyzer")
.TermVector(TermVectorOption.with_positions_offsets)
)
.DisableIndexField(false)
.DisableSizeField(false)
.Dynamic()
.Enabled()
.SourceField(s=>s
.SetDisabled(false)
.SetExcludes(new [] {"anyfromthis.prop.*"})
)
.IncludeInAll()
.Path("full")
.IdField(i => i
.SetIndex("not_analyzed")
.SetPath("myOtherId")
.SetStored(false)
)
.SourceField(s => s
.SetDisabled()
.SetCompression()
.SetCompressionTreshold("200b")
.SetExcludes(new[] { "path1.*" })
.SetIncludes(new[] { "path2.*" })
)
.TypeField(t => t
.SetIndexed()
.SetStored()
)
.AnalyzerField(a => a
.SetPath(p => p.Name)
.SetIndexed()
)
.BoostField(b => b
.SetName(p => p.LOC)
.SetNullValue(1.0)
)
.RoutingField(r => r
.SetPath(p => p.Country)
.SetRequired()
)
.TimestampField(t => t
.SetDisabled(false)
.SetPath(p => p.StartedOn)
)
.TtlField(t => t
.SetDisabled(false)
.SetDefault("1d")
)
.Meta(d=>d
.Add("attr1", "value1")
.Add("attr2", new { attr3 = "value3" })
)
.DynamicTemplates(d=>d
.Add(t=>t
.Name("template_1")
.Match("multi*")
.Mapping(tm=>tm
.MultiField(mf=>mf
.Fields(mff=>mff
.Generic(g => g
.Name("{name}")
.Type("{dynamic_type}")
.Index("analyzed")
.Store(false)
)
.Generic(g => g
.Name("org")
.Type("{dynamic_type}")
.Index("not_analyzed")
.Store()
)
.Generic(g => g
.Name("do_no_render_name_property", noNameProperty: true)
.Type("{dynamic_type}")
.Index("not_analyzed")
.Store()
)
)
)
)
)
)
.Properties(props => props
.String(s => s
.Name(p => p.Name)
.Similarity("mysimilarity")
.IndexName("my_crazy_name_i_want_in_lucene")
.IncludeInAll()
.Index(FieldIndexOption.analyzed)
.IndexAnalyzer("standard")
.IndexOptions(IndexOptions.positions)
.NullValue("my_special_null_value")
.OmitNorms()
.PositionOffsetGap(1)
.SearchAnalyzer("standard")
.Store()
.TermVector(TermVectorOption.with_positions_offsets)
.Boost(1.1)
.CopyTo(p => p.Content)
)
.Number(s => s
.Name(p => p.LOC)
.IndexName("lines_of_code")
.Type(NumberType.@integer)
.NullValue(0)
.Boost(2.0)
.IgnoreMalformed()
.IncludeInAll()
.Index()
.Store()
.PrecisionStep(1)
)
.Date(s => s
.Name(p => p.StartedOn)
.Format("dateOptionalTime")
.IgnoreMalformed()
.IncludeInAll()
.Index()
.IndexName("started_on_index_name")
.NullValue(new DateTime(1986, 3, 8))
.PrecisionStep(4)
.Store()
.Boost(1.3)
)
.Boolean(s => s
.Name(p => p.BoolValue) //reminder .Repository(string) exists too!
.Boost(1.4)
.IncludeInAll()
.Index()
.IndexName("bool_name_in_lucene_index")
.NullValue(false)
.Store()
)
.Binary(s => s
.Name(p => p.MyBinaryField)
.IndexName("binz")
)
.Attachment(s => s
.Name(p => p.MyAttachment)
.FileField(fs => fs.Index(FieldIndexOption.not_analyzed).Store())
.AuthorField(fs => fs.Index(FieldIndexOption.analyzed).Store(false))
.DateField(fs => fs.Store(false).IncludeInAll())
)
.Object<Person>(s => s
.Name(p => p.Followers.First())
.Dynamic()
.Enabled()
.IncludeInAll()
.MapFromAttributes()
.Path("full")
.Properties(pprops => pprops
.String(ps => ps.Name(p => p.FirstName).Index(FieldIndexOption.not_analyzed))
//etcetera
)
)
.NestedObject<Person>(s => s
.Name(p => p.NestedFollowers.First())
.Dynamic()
.Enabled()
.IncludeInAll()
.IncludeInParent()
.IncludeInRoot()
.MapFromAttributes()
.Path("full")
.Properties(pprops => pprops
.String(ps => ps.Name(p => p.FirstName).Index(FieldIndexOption.not_analyzed))
//etcetera
)
)
.MultiField(s => s
.Name(p => p.Name)
.Fields(pprops => pprops
.String(ps => ps.Name(p => p.Name).Index(FieldIndexOption.not_analyzed))
.String(ps => ps.Name(p => p.Name.Suffix("searchable")).Index(FieldIndexOption.analyzed))
)
)
.IP(s=>s
.Name(p=>p.PingIP)
.Boost(0.7)
.IncludeInAll()
.NoIndex()
.IndexName("ip")
.NullValue("0.0.0.0")
.PrecisionStep(4)
.Store()
)
.GeoPoint(s=>s
.Name(p=>p.Origin)
.IndexGeoHash()
.IndexLatLon()
.GeoHashPrecision(12)
)
.GeoShape(s => s
.Name(p => p.MyGeoShape)
.Tree(GeoTree.geohash)
.TreeLevels(2)
.DistanceErrorPercentage(0.025)
)
.Completion(s=>s
.Name(p=>p.Name.Suffix("completion"))
.IndexAnalyzer("standard")
.SearchAnalyzer("standard")
.MaxInputLength(20)
.Payloads()
.PreservePositionIncrements()
.PreserveSeparators()
)
)
);
Assert.NotNull(result.ConnectionStatus.Request);
}
}
}