Skip to content

Commit dc34350

Browse files
Merge remote-tracking branch 'origin/fix-H1s-per-seo-suggestions' into fix-H1s-per-seo-suggestions
2 parents 5b96ca0 + 95d0b67 commit dc34350

File tree

7 files changed

+86
-42
lines changed

7 files changed

+86
-42
lines changed

docs/reference/transport/rest-client/config/basic_authentication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mapped_pages:
44
navigation_title: Basic authentication
55
---
66

7-
# Basic authentication setup for {{es}} Java REST client [_basic_authentication]
7+
# Basic authentication setup for the {{es}} Java REST client [_basic_authentication]
88

99
:::{include} /reference/_snippets/legacy-rest-client.md
1010
:::

docs/reference/transport/rest-client/config/encrypted_communication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mapped_pages:
44
navigation_title: Encrypted communication
55
---
66

7-
# Encrypted communication and TLS setup in Java REST client [_encrypted_communication]
7+
# Encrypted communication and TLS setup in the {{es}} Java REST client [_encrypted_communication]
88

99
:::{include} /reference/_snippets/legacy-rest-client.md
1010
:::

docs/reference/transport/rest-client/config/node_selector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mapped_pages:
44
navigation_title: Node selector
55
---
66

7-
# Configuring node selector in the {{es}} Java REST client [_node_selector]
7+
# Configuring node selectors in the {{es}} Java REST client [_node_selector]
88

99
:::{include} /reference/_snippets/legacy-rest-client.md
1010
:::

docs/reference/transport/rest5-client/config/encrypted_communication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mapped_pages:
44
navigation_title: Encrypted communication
55
---
66

7-
# Encrypted communication and TLS setup in Java REST 5 client
7+
# Encrypted communication and TLS setup in the {{es}} Java REST 5 client
88

99
Encrypted communication using TLS can also be configured through the `HttpClientConfigCallback`. The [`org.apache.http.impl.nio.client.HttpAsyncClientBuilder`](https://hc.apache.org/httpcomponents-asyncclient-4.1.x/current/httpasyncclient/apidocs/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.html) received as an argument exposes multiple methods to configure encrypted communication: `setSSLContext`, `setSSLSessionStrategy` and `setConnectionManager`, in order of precedence from the least important.
1010

docs/reference/transport/rest5-client/config/node_selector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mapped_pages:
44
navigation_title: Node selector
55
---
66

7-
# Configuring node selector in the {{es}} Java REST 5 client
7+
# Configuring node selectors in the {{es}} Java REST 5 client
88

99
The client sends each request to one of the configured nodes in round-robin fashion. Nodes can optionally be filtered through a node selector that needs to be provided when initializing the client. This is useful when sniffing is enabled, in case no dedicated master nodes should be hit by HTTP requests. For each request the client will run the eventually configured node selector to filter the node candidates, then select the next one in the list out of the remaining ones.
1010

java-client/src/main/java/co/elastic/clients/elasticsearch/_types/SortOptions.java

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -302,48 +302,57 @@ public SortOptions build() {
302302
return new SortOptions(this);
303303
}
304304

305+
@Override
306+
public Builder withJson(JsonParser parser, JsonpMapper mapper) {
307+
deserializeBuilder(this, parser.next(), parser, mapper);
308+
return this;
309+
}
305310
}
306311

307312
public static final JsonpDeserializer<SortOptions> _DESERIALIZER = JsonpDeserializer.lazy(() -> JsonpDeserializer
308313
.of(EnumSet.of(JsonParser.Event.START_OBJECT, JsonParser.Event.VALUE_STRING), (parser, mapper, event) -> {
309314
SortOptions.Builder b = new SortOptions.Builder();
310-
311-
if (event == JsonParser.Event.VALUE_STRING) {
312-
switch (parser.getString()) {
313-
case "_score" :
314-
b.score(s -> s);
315-
break;
316-
case "_doc" :
317-
b.doc(d -> d);
318-
break;
319-
default :
320-
b.field(f -> f.field(parser.getString()));
321-
}
322-
return b.build();
323-
}
324-
325-
JsonpUtils.expectEvent(parser, JsonParser.Event.START_OBJECT, event);
326-
JsonpUtils.expectNextEvent(parser, JsonParser.Event.KEY_NAME);
327-
switch (parser.getString()) {
328-
case "_score" :
329-
b.score(ScoreSort._DESERIALIZER.deserialize(parser, mapper));
330-
break;
331-
case "_doc" :
332-
b.doc(ScoreSort._DESERIALIZER.deserialize(parser, mapper));
333-
break;
334-
case "_geo_distance" :
335-
b.geoDistance(GeoDistanceSort._DESERIALIZER.deserialize(parser, mapper));
336-
break;
337-
case "_script" :
338-
b.script(ScriptSort._DESERIALIZER.deserialize(parser, mapper));
339-
break;
340-
default :
341-
// Consumes END_OBJECT
342-
return b.field(FieldSort._DESERIALIZER.deserialize(parser, mapper, JsonParser.Event.KEY_NAME))
343-
.build();
344-
}
345-
346-
JsonpUtils.expectNextEvent(parser, JsonParser.Event.END_OBJECT);
315+
deserializeBuilder(b, event, parser, mapper);
347316
return b.build();
348317
}));
318+
319+
private static void deserializeBuilder(SortOptions.Builder b, JsonParser.Event event, JsonParser parser,
320+
JsonpMapper mapper) {
321+
if (event == JsonParser.Event.VALUE_STRING) {
322+
switch (parser.getString()) {
323+
case "_score" :
324+
b.score(s -> s);
325+
break;
326+
case "_doc" :
327+
b.doc(d -> d);
328+
break;
329+
default :
330+
b.field(f -> f.field(parser.getString()));
331+
}
332+
return;
333+
}
334+
335+
JsonpUtils.expectEvent(parser, JsonParser.Event.START_OBJECT, event);
336+
JsonpUtils.expectNextEvent(parser, JsonParser.Event.KEY_NAME);
337+
switch (parser.getString()) {
338+
case "_score" :
339+
b.score(ScoreSort._DESERIALIZER.deserialize(parser, mapper));
340+
break;
341+
case "_doc" :
342+
b.doc(ScoreSort._DESERIALIZER.deserialize(parser, mapper));
343+
break;
344+
case "_geo_distance" :
345+
b.geoDistance(GeoDistanceSort._DESERIALIZER.deserialize(parser, mapper));
346+
break;
347+
case "_script" :
348+
b.script(ScriptSort._DESERIALIZER.deserialize(parser, mapper));
349+
break;
350+
default :
351+
// Consumes END_OBJECT
352+
b.field(FieldSort._DESERIALIZER.deserialize(parser, mapper, JsonParser.Event.KEY_NAME));
353+
return;
354+
}
355+
356+
JsonpUtils.expectNextEvent(parser, JsonParser.Event.END_OBJECT);
357+
}
349358
}

java-client/src/test/java/co/elastic/clients/elasticsearch/model/SerializationTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package co.elastic.clients.elasticsearch.model;
2121

22+
import co.elastic.clients.elasticsearch._types.SortOptions;
2223
import co.elastic.clients.elasticsearch.cat.NodesResponse;
2324
import co.elastic.clients.elasticsearch.core.GetSourceResponse;
2425
import co.elastic.clients.json.JsonpDeserializable;
@@ -131,4 +132,38 @@ public void testJsonpValuesToString() {
131132
JsonpUtils.toString(Json.createObjectBuilder().build());
132133
});
133134
}
135+
136+
@Test
137+
public void testSortOptionsDeserializer() {
138+
139+
String customField = """
140+
{
141+
"term" : "asc"
142+
}
143+
""";
144+
145+
SortOptions so = SortOptions.of(b->b.withJson(new StringReader(customField)));
146+
147+
String score = """
148+
"_score"
149+
""";
150+
151+
so = SortOptions.of(b->b.withJson(new StringReader(score)));
152+
153+
String geoDistance = """
154+
{
155+
"_geo_distance" : {
156+
"pin.location" : "<-70>, <40>",
157+
"order" : "asc",
158+
"unit" : "km",
159+
"mode" : "min",
160+
"distance_type" : "arc",
161+
"ignore_unmapped": true
162+
}
163+
}
164+
""";
165+
166+
so = SortOptions.of(b->b.withJson(new StringReader(geoDistance)));
167+
168+
}
134169
}

0 commit comments

Comments
 (0)