Skip to content

Commit e469211

Browse files
committed
Update Id inference docs
This commit updates the Id inference docs to pull the disabling of Id inference out into its own section
1 parent 7cd229e commit e469211

File tree

5 files changed

+97
-43
lines changed

5 files changed

+97
-43
lines changed

docs/client-concepts/high-level/inference/ids-inference.asciidoc

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This is a special type that you can implicitly convert to from the following typ
2828

2929
* `Guid`
3030

31-
Methods that take an `Id` can be passed any of these types and it will be implicitly converted to an instance of `Id`
31+
Methods that take an `Id` can be passed any of these types and they will be implicitly converted to an instance of `Id`
3232

3333
[source,csharp]
3434
----
@@ -43,9 +43,10 @@ Expect("hello-world").WhenSerializing(idFromString);
4343
Expect("d70bd3cf-4e38-46f3-91ca-fcbef29b148e").WhenSerializing(idFromGuid);
4444
----
4545

46-
==== Inferring from a type
46+
==== Inferring Id from a type
4747

48-
Sometimes a method takes an object and we need an Id from that object to build up a path.
48+
Sometimes a method takes an object instance and the client requires an `Id` from that
49+
instance to build up a path.
4950
There is no implicit conversion from any object to `Id`, but we can call `Id.From`.
5051

5152
Imagine your codebase has the following type that we want to index into Elasticsearch
@@ -114,7 +115,7 @@ WithConnectionSettings(x => x
114115

115116
==== Using the ElasticsearchType attribute
116117

117-
Another way is to mark the type with an `ElasticsearchType` attribute, setting `IdProperty`
118+
Another way to control Id inference is to mark the type with an `ElasticsearchType` attribute, setting `IdProperty`
118119
to the name of the property that should be used for the document id
119120

120121
[source,csharp]
@@ -144,8 +145,10 @@ Expect("x").WhenInferringIdOn(dto);
144145

145146
==== Using Mapping inference on ConnectionSettings
146147

147-
This attribute *is* cached statically/globally, however an inference rule on the `ConnectionSettings` for the type will
148-
still win over the attribute. Here we demonstrate this by creating a different `ConnectionSettings` instance
148+
This attribute *is* cached statically/globally, however an inference rule on `ConnectionSettings` for the type will
149+
still win over the attribute.
150+
151+
Here we demonstrate this by creating a different `ConnectionSettings` instance
149152
that will infer the document id from the property `OtherName`:
150153

151154
[source,csharp]
@@ -157,3 +160,36 @@ WithConnectionSettings(x => x
157160
).Expect("y").WhenInferringIdOn(dto);
158161
----
159162

163+
==== Disabling Id inference
164+
165+
You can configure the client to disable Id inference on a CLR type basis
166+
167+
[source,csharp]
168+
----
169+
WithConnectionSettings(x => x
170+
.DefaultMappingFor<MyOtherDTO>(m => m
171+
.DisableIdInference()
172+
)
173+
).Expect(null).WhenInferringIdOn(dto);
174+
----
175+
176+
or globally for all types
177+
178+
[source,csharp]
179+
----
180+
WithConnectionSettings(x => x.DefaultDisableIdInference())
181+
.Expect(null).WhenInferringIdOn(dto);
182+
----
183+
184+
Once disabled globally, Id inference cannot be enabled per type
185+
186+
[source,csharp]
187+
----
188+
WithConnectionSettings(x => x
189+
.DefaultDisableIdInference()
190+
.DefaultMappingFor<MyOtherDTO>(m => m
191+
.DisableIdInference(disable: false)
192+
)
193+
).Expect(null).WhenInferringIdOn(dto);
194+
----
195+

docs/code-standards/descriptors.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ var methods = from d in YieldAllDescriptors()
198198
where !(m.Name == nameof(ScoreFunctionsDescriptor<object>.Weight) && dt == typeof(ScoreFunctionsDescriptor<>))
199199
where !(m.Name == nameof(SortDescriptor<object>.Ascending) && dt == typeof(SortDescriptor<>))
200200
where !(m.Name == nameof(SortDescriptor<object>.Descending) && dt == typeof(SortDescriptor<>))
201-
201+
where !(m.Name == nameof(ClrTypeMappingDescriptor<object>.DisableIdInference) && dt == typeof(ClrTypeMappingDescriptor<>))
202+
where !(m.Name == nameof(ClrTypeMappingDescriptor.DisableIdInference) && dt == typeof(ClrTypeMappingDescriptor))
202203
203204
select new {m, d, p};
204205

docs/code-standards/naming-conventions.asciidoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ var exceptions = new[] <1>
118118
typeof(IndicesShardStoresRequest),
119119
typeof(RenderSearchTemplateRequest),
120120
typeof(MultiSearchTemplateRequest),
121-
typeof(CreateRequest<>)
121+
typeof(CreateRequest<>),
122+
typeof(DeleteByQueryRethrottleRequest), // uses ListTasksResponse
123+
typeof(UpdateByQueryRethrottleRequest) // uses ListTasksResponse
122124
};
123125
124126
var types = typeof(IRequest).Assembly().GetTypes();

docs/query-dsl/full-text/match/match-usage.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ q
2626
.Boost(1.1)
2727
.CutoffFrequency(0.001)
2828
.Query("hello world")
29-
.Fuzziness(Fuzziness.Auto)
29+
.Fuzziness(Fuzziness.AutoLength(3, 6))
3030
.Lenient()
3131
.FuzzyTranspositions()
3232
.MinimumShouldMatch(2)
@@ -48,7 +48,7 @@ new MatchQuery
4848
Name = "named_query",
4949
CutoffFrequency = 0.001,
5050
Query = "hello world",
51-
Fuzziness = Fuzziness.Auto,
51+
Fuzziness = Fuzziness.AutoLength(3, 6),
5252
FuzzyTranspositions = true,
5353
MinimumShouldMatch = 2,
5454
FuzzyRewrite = MultiTermQueryRewrite.TopTermsBlendedFreqs(10),
@@ -68,7 +68,7 @@ new MatchQuery
6868
"query": "hello world",
6969
"analyzer": "standard",
7070
"fuzzy_rewrite": "top_terms_blended_freqs_10",
71-
"fuzziness": "AUTO",
71+
"fuzziness": "AUTO:3,6",
7272
"fuzzy_transpositions": true,
7373
"cutoff_frequency": 0.001,
7474
"lenient": true,

src/Tests/Tests/ClientConcepts/HighLevel/Inference/IdsInference.doc.cs

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class IdsInference
2121
* - `String`
2222
* - `Guid`
2323
*
24-
* Methods that take an `Id` can be passed any of these types and it will be implicitly converted to an instance of `Id`
24+
* Methods that take an `Id` can be passed any of these types and they will be implicitly converted to an instance of `Id`
2525
*/
2626
[U] public void CanImplicitlyConvertToId()
2727
{
@@ -37,9 +37,10 @@ [U] public void CanImplicitlyConvertToId()
3737
}
3838

3939
/**
40-
* ==== Inferring from a type
40+
* ==== Inferring Id from a type
4141
*
42-
* Sometimes a method takes an object and we need an Id from that object to build up a path.
42+
* Sometimes a method takes an object instance and the client requires an `Id` from that
43+
* instance to build up a path.
4344
* There is no implicit conversion from any object to `Id`, but we can call `Id.From`.
4445
*
4546
* Imagine your codebase has the following type that we want to index into Elasticsearch
@@ -94,38 +95,12 @@ [U] public void CanGetIdFromDocument()
9495
.IdProperty(typeof(MyDTO).GetProperty(nameof(MyDTO.Name)).Name)
9596
)
9697
).Expect("x").WhenInferringIdOn(dto);
97-
98-
/**
99-
* You can configure the client to disable this Id inference behaviour per type:
100-
*/
101-
WithConnectionSettings(x => x
102-
.DefaultMappingFor<MyDTO>(m => m
103-
.DisableIdInference()
104-
)
105-
).Expect(null).WhenInferringIdOn(dto);
106-
107-
/**
108-
* or globally type:
109-
*/
110-
WithConnectionSettings(x => x.DefaultDisableIdInference())
111-
.Expect(null).WhenInferringIdOn(dto);
112-
113-
/**
114-
* Once disabled globally the id inference can not be enabled per type.
115-
*/
116-
WithConnectionSettings(x => x
117-
.DefaultDisableIdInference()
118-
.DefaultMappingFor<MyDTO>(m => m
119-
.DisableIdInference(disable: false)
120-
)
121-
).Expect(null).WhenInferringIdOn(dto);
122-
12398
}
12499

125100
/**
126101
* ==== Using the ElasticsearchType attribute
127102
*
128-
* Another way is to mark the type with an `ElasticsearchType` attribute, setting `IdProperty`
103+
* Another way to control Id inference is to mark the type with an `ElasticsearchType` attribute, setting `IdProperty`
129104
* to the name of the property that should be used for the document id
130105
*/
131106
[ElasticsearchType(IdProperty = nameof(Name))]
@@ -151,8 +126,10 @@ [U] public void CanGetIdFromAttribute()
151126
/**
152127
* ==== Using Mapping inference on ConnectionSettings
153128
*
154-
* This attribute *is* cached statically/globally, however an inference rule on the `ConnectionSettings` for the type will
155-
* still win over the attribute. Here we demonstrate this by creating a different `ConnectionSettings` instance
129+
* This attribute *is* cached statically/globally, however an inference rule on `ConnectionSettings` for the type will
130+
* still win over the attribute.
131+
*
132+
* Here we demonstrate this by creating a different `ConnectionSettings` instance
156133
* that will infer the document id from the property `OtherName`:
157134
*/
158135
WithConnectionSettings(x => x
@@ -161,5 +138,43 @@ [U] public void CanGetIdFromAttribute()
161138
)
162139
).Expect("y").WhenInferringIdOn(dto);
163140
}
141+
142+
/** ==== Disabling Id inference
143+
*/
144+
[U] public void DisablingIdInference()
145+
{
146+
// hide
147+
var dto = new MyOtherDTO
148+
{
149+
Id = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"),
150+
Name = "x",
151+
OtherName = "y"
152+
};
153+
154+
/**
155+
* You can configure the client to disable Id inference on a CLR type basis
156+
*/
157+
WithConnectionSettings(x => x
158+
.DefaultMappingFor<MyOtherDTO>(m => m
159+
.DisableIdInference()
160+
)
161+
).Expect(null).WhenInferringIdOn(dto);
162+
163+
/**
164+
* or globally for all types
165+
*/
166+
WithConnectionSettings(x => x.DefaultDisableIdInference())
167+
.Expect(null).WhenInferringIdOn(dto);
168+
169+
/**
170+
* Once disabled globally, Id inference cannot be enabled per type
171+
*/
172+
WithConnectionSettings(x => x
173+
.DefaultDisableIdInference()
174+
.DefaultMappingFor<MyOtherDTO>(m => m
175+
.DisableIdInference(disable: false)
176+
)
177+
).Expect(null).WhenInferringIdOn(dto);
178+
}
164179
}
165180
}

0 commit comments

Comments
 (0)