Skip to content

Commit df8ba67

Browse files
Add docs about MissingRequiredPropertyException (#301) (#303)
Co-authored-by: Sylvain Wallez <sylvain@elastic.co>
1 parent a9a29ca commit df8ba67

File tree

6 files changed

+53
-10
lines changed

6 files changed

+53
-10
lines changed

docs/api-conventions/exceptions.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[[exceptions]]
1+
[[exception-conventions]]
22
=== Exceptions
33

44
Client methods can throw two kinds of exceptions:

docs/api-conventions/index.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ to process. The sections below explain these in details.
1515
ifdef::is_main_branch,v8_1_1_released,v7_17_2_released[]
1616
* <<loading-json>>
1717
endif::is_main_branch,v8_1_1_released,v7_17_2_released[]
18-
* <<exceptions>>
18+
* <<exception-conventions>>
1919

2020
include::package-structure.asciidoc[]
2121
include::method-naming.asciidoc[]

docs/index.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ include::api-conventions/index.asciidoc[]
3232

3333
include::usage/index.asciidoc[]
3434

35-
// include::troubleshooting/index.asciidoc[]
35+
include::troubleshooting/index.asciidoc[]
3636
include::javadoc-and-source.asciidoc[]
3737
include::release-notes.asciidoc[]
3838
include::external-resources.asciidoc[]

docs/troubleshooting/index.asciidoc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
[[troubleshooting]]
12
== Troubleshooting
23

3-
=== Understanding exceptions
4+
// * <<debugging>>
5+
// * <<deprecation-warnings>>
46

5-
TBD
7+
.Exceptions
68

7-
=== Debugging
9+
* <<missing-required-property>>
810

9-
TBD
1011

11-
=== Elasticsearch deprecation warnings
12+
// [[debugging]]
13+
// === Debugging
1214

13-
TBD
15+
//[[deprecation-warnings]]
16+
// === Elasticsearch deprecation warnings
17+
18+
include::missing-required-property.asciidoc[]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[[missing-required-property]]
2+
=== `MissingRequiredPropertyException` in a response
3+
4+
The {java-client} distinguishes optional and required properties. Optional properties are marked with the `@Nullable` annotation.
5+
6+
When an API object is built and a required property hasn't been set, a `MissingRequiredPropertyException` is thrown. This applies both to request object built by your application and to response objects returned by Elasticsearch, so that you can be assured that a property that does not have the `@Nullable` annotation will never be `null`.
7+
8+
However, there may be bugs in the https://github.com/elastic/elasticsearch-specification[Elasticsearch API specification] where a response object's property is incorrectly required, leading to a `MissingRequiredPropertyException` when deserializing a response. If this happens, here's how you can work around it:
9+
10+
* Make sure you use the latest release of the {java-client}. The issue may already have been fixed.
11+
* If the issue is still present on the latest version, https://github.com/elastic/elasticsearch-java/issues/new/choose[open an issue] so that we can fix it in the next release. Please help us to improve the {java-client}.
12+
* Temporarily disable required property checks for the offending request:
13+
14+
WARNING: This is a workaround. Do not consider this as a permanent solution, and please https://github.com/elastic/elasticsearch-java/issues/new/choose[open an issue] so that the problem can be fixed in a future release.
15+
16+
["source","java"]
17+
--------------------------------------------------
18+
ApiTypeHelper.DANGEROUS_disableRequiredPropertiesCheck(true);
19+
SomeRequest request = SomeRequest.of(...);
20+
SomeResponse response = esClient.someApi(request);
21+
ApiTypeHelper.DANGEROUS_disableRequiredPropertiesCheck(false);
22+
// Do something with response
23+
}
24+
--------------------------------------------------
25+
26+
The `DANGEROUS_disableRequiredPropertiesCheck` method disables required property checks on the current thread, and for response deserialization in asynchronous requests. As its name implies, it is dangerous as it removes the guarantees of properties that are not `@Nullable`. This is a temporary workaround until the issue is fixed.
27+
28+
Note that the result of this method is an `AutoCloseable` object that resets required property checks to its previous setting. You can therefore use it in a try-with-resource block as follows:
29+
30+
["source","java"]
31+
--------------------------------------------------
32+
try (ApiTypeHelper.DisabledChecksHandle h =
33+
ApiTypeHelper.DANGEROUS_disableRequiredPropertiesCheck(true)) {
34+
SomeRequest request = SomeRequest.of(...);
35+
SomeResponse response = esClient.someApi(request);
36+
// Do something with response
37+
}
38+
--------------------------------------------------

docs/usage/aggregations.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
An aggregation summarizes your data as metrics, statistics, or other analytics.
55

6-
NOTE: See the es-docs}/search-aggregations[{es} documentation] for a full explanation of aggregations.
6+
NOTE: See the {es-docs}/search-aggregations.html[{es} documentation] for a full explanation of aggregations.
77

88
[discrete]
99
==== A simple aggregation

0 commit comments

Comments
 (0)