You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var descriptor = new CreateIndexDescriptor("myindex")
54
+
var createIndexResponse = client.CreateIndex("myindex", c => c
55
55
.Mappings(ms => ms
56
56
.Map<Company>(m => m.AutoMap()) <1>
57
57
.Map<Employee>(m => m.AutoMap()) <2>
58
-
);
58
+
)
59
+
);
59
60
----
60
61
<1> Auto map `Company`
61
62
62
63
<2> Auto map `Employee`
63
64
65
+
This produces the following JSON request
66
+
64
67
[source,javascript]
65
68
----
66
69
{
@@ -159,6 +162,51 @@ var descriptor = new CreateIndexDescriptor("myindex")
159
162
}
160
163
----
161
164
165
+
[source,csharp]
166
+
----
167
+
var connectionSettings = new ConnectionSettings(new InMemoryConnection()) <1>
168
+
.DisableDirectStreaming() <2>
169
+
.InferMappingFor<ParentWithStringId>(m => m
170
+
.TypeName("parent")
171
+
.Ignore(p => p.Description)
172
+
.Ignore(p => p.IgnoreMe)
173
+
);
174
+
175
+
var client = new ElasticClient(connectionSettings);
176
+
177
+
var createIndexResponse = client.CreateIndex("myindex", c => c
178
+
.Mappings(ms => ms
179
+
.Map<ParentWithStringId>(m => m
180
+
.AutoMap()
181
+
)
182
+
)
183
+
);
184
+
----
185
+
<1> we're using an _in memory_ connection for this example. In your production application though, you'll want to use an `IConnection` that actually sends a request.
186
+
187
+
<2> we disable direct streaming here to capture the request and response bytes. In your production application however, you'll likely not want to do this, since it causes the request and response bytes to be buffered in memory.
188
+
189
+
[source,javascript]
190
+
----
191
+
{
192
+
"mappings": {
193
+
"parent": {
194
+
"properties": {
195
+
"id": {
196
+
"type": "text",
197
+
"fields": {
198
+
"keyword": {
199
+
"ignore_above": 256,
200
+
"type": "keyword"
201
+
}
202
+
}
203
+
}
204
+
}
205
+
}
206
+
}
207
+
}
208
+
----
209
+
162
210
Observe that NEST has inferred the Elasticsearch types based on the CLR type of our POCO properties.
163
211
In this example,
164
212
@@ -177,57 +225,105 @@ sub field.
177
225
178
226
NEST has inferred mapping support for the following .NET types
179
227
180
-
* `String` maps to `"text"` with a `"keyword"` sub field. See <<multi-fields, Multi Fields>>.
228
+
[horizontal]
229
+
`String`::
230
+
231
+
maps to `"text"` with a `"keyword"` sub field. See <<multi-fields, Multi Fields>>.
232
+
233
+
`Int32`::
234
+
235
+
maps to `"integer"`
236
+
237
+
`UInt16`::
238
+
239
+
maps to `"integer"`
240
+
241
+
`Int16`::
242
+
243
+
maps to `"short"`
244
+
245
+
`Byte`::
246
+
247
+
maps to `"short"`
248
+
249
+
`Int64`::
250
+
251
+
maps to `"long"`
252
+
253
+
`UInt32`::
181
254
182
-
* `Int32` maps to `"integer"`
255
+
maps to `"long"`
183
256
184
-
* `UInt16` maps to `"integer"`
257
+
`TimeSpan`::
185
258
186
-
* `Int16` maps to `"short"`
259
+
maps to `"long"`
187
260
188
-
* `Byte` maps to `"short"`
261
+
`Single`::
189
262
190
-
* `Int64` maps to `"long"`
263
+
maps to `"float"`
191
264
192
-
* `UInt32` maps to `"long"`
265
+
`Double`::
193
266
194
-
* `TimeSpan` maps to `"long"`
267
+
maps to `"double"`
195
268
196
-
* `Single` maps to `"float"`
269
+
`Decimal`::
197
270
198
-
* `Double` maps to `"double"`
271
+
maps to `"double"`
199
272
200
-
* `Decimal` maps to `"double"`
273
+
`UInt64`::
201
274
202
-
* `UInt64` maps to `"double"`
275
+
maps to `"double"`
203
276
204
-
* `DateTime` maps to `"date"`
277
+
`DateTime`::
205
278
206
-
* `DateTimeOffset` maps to `"date"`
279
+
maps to `"date"`
207
280
208
-
* `Boolean` maps to `"boolean"`
281
+
`DateTimeOffset`::
209
282
210
-
* `Char` maps to `"keyword"`
283
+
maps to `"date"`
211
284
212
-
* `Guid` maps to `"keyword"`
285
+
`Boolean`::
286
+
287
+
maps to `"boolean"`
288
+
289
+
`Char`::
290
+
291
+
maps to `"keyword"`
292
+
293
+
`Guid`::
294
+
295
+
maps to `"keyword"`
213
296
214
297
and supports a number of special types defined in NEST
215
298
216
-
* `Nest.GeoLocation` maps to `"geo_point"`
299
+
[horizontal]
300
+
`Nest.GeoLocation`::
301
+
302
+
maps to `"geo_point"`
303
+
304
+
`Nest.CompletionField`::
217
305
218
-
* `Nest.CompletionField` maps to `"completion"`
306
+
maps to `"completion"`
219
307
220
-
* `Nest.Attachment` maps to `"attachment"`
308
+
`Nest.DateRange`::
221
309
222
-
* `Nest.DateRange` maps to `"date_range"`
310
+
maps to `"date_range"`
223
311
224
-
* `Nest.DoubleRange` maps to `"double_range"`
312
+
`Nest.DoubleRange`::
225
313
226
-
* `Nest.FloatRange` maps to `"float_range"`
314
+
maps to `"double_range"`
227
315
228
-
* `Nest.IntegerRange` maps to `"integer_range"`
316
+
`Nest.FloatRange`::
229
317
230
-
* `Nest.LongRange` maps to `"long_range"`
318
+
maps to `"float_range"`
319
+
320
+
`Nest.IntegerRange`::
321
+
322
+
maps to `"integer_range"`
323
+
324
+
`Nest.LongRange`::
325
+
326
+
maps to `"long_range"`
231
327
232
328
All other types map to `"object"` by default.
233
329
@@ -282,10 +378,11 @@ By default, `.AutoMap()` only goes as far as depth 1
282
378
283
379
[source,csharp]
284
380
----
285
-
var descriptor = new CreateIndexDescriptor("myindex")
381
+
var createIndexResponse = client.CreateIndex("myindex", c => c
286
382
.Mappings(ms => ms
287
383
.Map<A>(m => m.AutoMap())
288
-
);
384
+
)
385
+
);
289
386
----
290
387
291
388
Thus we do not map properties on the second occurrence of our Child property
@@ -310,10 +407,11 @@ Now let's specify a maxRecursion of `3`
310
407
311
408
[source,csharp]
312
409
----
313
-
var withMaxRecursionDescriptor = new CreateIndexDescriptor("myindex")
410
+
createIndexResponse = client.CreateIndex("myindex", c => c
314
411
.Mappings(ms => ms
315
412
.Map<A>(m => m.AutoMap(3))
316
-
);
413
+
)
414
+
);
317
415
----
318
416
319
417
`.AutoMap()` has now mapped three levels of our Child property
0 commit comments