Skip to content

Commit 2d5c0d5

Browse files
committed
Use client calls in automapping documentation
Closes #2960 (cherry picked from commit cbfd037)
1 parent 7097f6e commit 2d5c0d5

File tree

13 files changed

+421
-267
lines changed

13 files changed

+421
-267
lines changed

docs/client-concepts/certificates/working-with-certificates.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class AllowAllCertificatesCluster : SslAndKpiXPackCluster
8080
If your client application has access to the public CA certificate locally, Elasticsearch.NET and NEST ship with some handy helpers
8181
that can assert that a certificate the server presents is one that came from the local CA.
8282

83-
If you use X-Pack's {ref_current}/certutil.html[+certutil+ tool] to generate SSL certificates, the generated node certificate
83+
If you use X-Pack's {ref_current}/certutil.html`certutil` tool] to generate SSL certificates, the generated node certificate
8484
does not include the CA in the certificate chain, in order to cut down on SSL handshake size. In those case you can use`CertificateValidations.AuthorityIsRoot` and pass it your local copy of the CA public key to assert that
8585
the certificate the server presented was generated using it
8686

@@ -115,7 +115,7 @@ the local CA certificate is part of the chain that was used to generate the serv
115115
==== Client Certificates
116116

117117
X-Pack also allows you to configure a {xpack_current}/pki-realm.html[PKI realm] to enable user authentication
118-
through client certificates. The {ref_current}/certutil.html[+certutil+ tool] included with X-Pack allows you to
118+
through client certificates. The {ref_current}/certutil.html`certutil` tool] included with X-Pack allows you to
119119
generate client certificates as well and assign the distinguished name (DN) of the
120120
certificate to a user with a certain role.
121121

docs/client-concepts/high-level/mapping/attribute-mapping.asciidoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class Employee
6565
public bool IsManager { get; set; }
6666
6767
[Nested]
68-
[PropertyName("empl"), JsonProperty("empl")]
68+
[PropertyName("empl")]
6969
public List<Employee> Employees { get; set; }
7070
}
7171
----
@@ -74,11 +74,12 @@ Then we map the types by calling `.AutoMap()`
7474

7575
[source,csharp]
7676
----
77-
var descriptor = new CreateIndexDescriptor("myindex")
77+
var createIndexResponse = client.CreateIndex("myindex", c => c
7878
.Mappings(ms => ms
7979
.Map<Company>(m => m.AutoMap())
8080
.Map<Employee>(m => m.AutoMap())
81-
);
81+
)
82+
);
8283
----
8384

8485
[source,javascript]

docs/client-concepts/high-level/mapping/auto-map.asciidoc

Lines changed: 121 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@ for the base class and then call AutoMap foreach of the types we want it it the
5454

5555
[source,csharp]
5656
----
57-
var descriptor = new CreateIndexDescriptor("myindex")
57+
var createIndexResponse = client.CreateIndex("myindex", c => c
5858
.Mappings(ms => ms
5959
.Map<Document>(m => m
6060
.AutoMap<Company>() <1>
61-
.AutoMap<Employee>() <2>
61+
.AutoMap(typeof(Employee)) <2>
6262
)
63-
);
63+
)
64+
);
6465
----
65-
<1> Auto map `Company`
66+
<1> Auto map `Company` using the generic method
67+
68+
<2> Auto map `Employee` using the non-generic method
6669

67-
<2> Auto map `Employee`
70+
This produces the following JSON request
6871

6972
[source,javascript]
7073
----
@@ -153,47 +156,47 @@ public class ParentWithStringId : IgnoringProperties.Parent
153156
public new string Id { get; set; }
154157
}
155158
156-
var descriptor = new CreateIndexDescriptor("myindex")
157-
.Mappings(ms => ms
158-
.Map<ParentWithStringId>(m => m
159-
.AutoMap()
160-
)
161-
);
162-
163-
var expected = new
164-
{
165-
mappings = new
166-
{
167-
parent = new
168-
{
169-
properties = new
170-
{
171-
id = new
172-
{
173-
type = "text",
174-
fields = new
175-
{
176-
keyword = new
177-
{
178-
ignore_above = 256,
179-
type = "keyword"
180-
}
181-
}
182-
}
183-
}
184-
}
185-
}
186-
};
187-
188-
var settings = WithConnectionSettings(s => s
159+
var connectionSettings = new ConnectionSettings(new InMemoryConnection()) <1>
160+
.DisableDirectStreaming() <2>
189161
.DefaultMappingFor<ParentWithStringId>(m => m
190162
.TypeName("parent")
191163
.Ignore(p => p.Description)
192164
.Ignore(p => p.IgnoreMe)
165+
);
166+
167+
var client = new ElasticClient(connectionSettings);
168+
169+
var createIndexResponse = client.CreateIndex("myindex", c => c
170+
.Mappings(ms => ms
171+
.Map<ParentWithStringId>(m => m
172+
.AutoMap()
173+
)
193174
)
194175
);
176+
----
177+
<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.
178+
179+
<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.
195180

196-
settings.Expect(expected).WhenSerializing((ICreateIndexRequest) descriptor);
181+
[source,javascript]
182+
----
183+
{
184+
"mappings": {
185+
"parent": {
186+
"properties": {
187+
"id": {
188+
"type": "text",
189+
"fields": {
190+
"keyword": {
191+
"ignore_above": 256,
192+
"type": "keyword"
193+
}
194+
}
195+
}
196+
}
197+
}
198+
}
199+
}
197200
----
198201

199202
Observe that NEST has inferred the Elasticsearch types based on the CLR type of our POCO properties.
@@ -214,57 +217,105 @@ sub field.
214217

215218
NEST has inferred mapping support for the following .NET types
216219

217-
* `String` maps to `"text"` with a `"keyword"` sub field. See <<multi-fields, Multi Fields>>.
220+
[horizontal]
221+
`String`::
222+
223+
maps to `"text"` with a `"keyword"` sub field. See <<multi-fields, Multi Fields>>.
224+
225+
`Int32`::
226+
227+
maps to `"integer"`
228+
229+
`UInt16`::
230+
231+
maps to `"integer"`
232+
233+
`Int16`::
234+
235+
maps to `"short"`
236+
237+
`Byte`::
238+
239+
maps to `"short"`
240+
241+
`Int64`::
218242

219-
* `Int32` maps to `"integer"`
243+
maps to `"long"`
220244

221-
* `UInt16` maps to `"integer"`
245+
`UInt32`::
222246

223-
* `Int16` maps to `"short"`
247+
maps to `"long"`
224248

225-
* `Byte` maps to `"short"`
249+
`TimeSpan`::
226250

227-
* `Int64` maps to `"long"`
251+
maps to `"long"`
228252

229-
* `UInt32` maps to `"long"`
253+
`Single`::
230254

231-
* `TimeSpan` maps to `"long"`
255+
maps to `"float"`
232256

233-
* `Single` maps to `"float"`
257+
`Double`::
234258

235-
* `Double` maps to `"double"`
259+
maps to `"double"`
236260

237-
* `Decimal` maps to `"double"`
261+
`Decimal`::
238262

239-
* `UInt64` maps to `"double"`
263+
maps to `"double"`
240264

241-
* `DateTime` maps to `"date"`
265+
`UInt64`::
242266

243-
* `DateTimeOffset` maps to `"date"`
267+
maps to `"double"`
244268

245-
* `Boolean` maps to `"boolean"`
269+
`DateTime`::
246270

247-
* `Char` maps to `"keyword"`
271+
maps to `"date"`
248272

249-
* `Guid` maps to `"keyword"`
273+
`DateTimeOffset`::
274+
275+
maps to `"date"`
276+
277+
`Boolean`::
278+
279+
maps to `"boolean"`
280+
281+
`Char`::
282+
283+
maps to `"keyword"`
284+
285+
`Guid`::
286+
287+
maps to `"keyword"`
250288

251289
and supports a number of special types defined in NEST
252290

253-
* `Nest.GeoLocation` maps to `"geo_point"`
291+
[horizontal]
292+
`Nest.GeoLocation`::
293+
294+
maps to `"geo_point"`
254295

255-
* `Nest.CompletionField` maps to `"completion"`
296+
`Nest.CompletionField`::
256297

257-
* `Nest.Attachment` maps to `"attachment"`
298+
maps to `"completion"`
258299

259-
* `Nest.DateRange` maps to `"date_range"`
300+
`Nest.DateRange`::
260301

261-
* `Nest.DoubleRange` maps to `"double_range"`
302+
maps to `"date_range"`
262303

263-
* `Nest.FloatRange` maps to `"float_range"`
304+
`Nest.DoubleRange`::
264305

265-
* `Nest.IntegerRange` maps to `"integer_range"`
306+
maps to `"double_range"`
266307

267-
* `Nest.LongRange` maps to `"long_range"`
308+
`Nest.FloatRange`::
309+
310+
maps to `"float_range"`
311+
312+
`Nest.IntegerRange`::
313+
314+
maps to `"integer_range"`
315+
316+
`Nest.LongRange`::
317+
318+
maps to `"long_range"`
268319

269320
All other types map to `"object"` by default.
270321

@@ -319,10 +370,11 @@ By default, `.AutoMap()` only goes as far as depth 1
319370

320371
[source,csharp]
321372
----
322-
var descriptor = new CreateIndexDescriptor("myindex")
373+
var createIndexResponse = client.CreateIndex("myindex", c => c
323374
.Mappings(ms => ms
324375
.Map<A>(m => m.AutoMap())
325-
);
376+
)
377+
);
326378
----
327379

328380
Thus we do not map properties on the second occurrence of our Child property
@@ -347,10 +399,11 @@ Now let's specify a maxRecursion of `3`
347399

348400
[source,csharp]
349401
----
350-
var withMaxRecursionDescriptor = new CreateIndexDescriptor("myindex")
402+
createIndexResponse = client.CreateIndex("myindex", c => c
351403
.Mappings(ms => ms
352404
.Map<A>(m => m.AutoMap(3))
353-
);
405+
)
406+
);
354407
----
355408

356409
`.AutoMap()` has now mapped three levels of our Child property

0 commit comments

Comments
 (0)