Skip to content

Commit 6c1d542

Browse files
Merge branch 'main' into security-entity-store-permissions
2 parents c2a498a + cd0f9a4 commit 6c1d542

File tree

73 files changed

+2263
-493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2263
-493
lines changed

docs/changelog/112567.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 112567
2+
summary: Track shard snapshot progress during node shutdown
3+
area: Snapshot/Restore
4+
type: enhancement
5+
issues: []

docs/changelog/113900.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/changelog/114128.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 114128
2+
summary: Adding `index_template_substitutions` to the simulate ingest API
3+
area: Ingest Node
4+
type: enhancement
5+
issues: []

docs/reference/indices/forcemerge.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ documents can't be backed up incrementally.
5656
===== Blocks during a force merge
5757

5858
Calls to this API block until the merge is complete (unless request contains
59-
wait_for_completion=false, which is default true). If the client connection
59+
`wait_for_completion=false`, which is default `true`). If the client connection
6060
is lost before completion then the force merge process will continue in the
6161
background. Any new requests to force merge the same indices will also block
6262
until the ongoing force merge is complete.

docs/reference/indices/put-index-template.asciidoc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ include::{docdir}/rest-api/common-parms.asciidoc[tag=master-timeout]
8585
[[put-index-template-api-request-body]]
8686
==== {api-request-body-title}
8787

88+
// tag::request-body[]
89+
8890
`composed_of`::
8991
(Optional, array of strings)
9092
An ordered list of component template names. Component templates are merged in the order
@@ -102,7 +104,7 @@ See <<create-index-template,create an index template>>.
102104
+
103105
.Properties of `data_stream`
104106
[%collapsible%open]
105-
====
107+
=====
106108
`allow_custom_routing`::
107109
(Optional, Boolean) If `true`, the data stream supports
108110
<<mapping-routing-field,custom routing>>. Defaults to `false`.
@@ -117,7 +119,7 @@ See <<create-index-template,create an index template>>.
117119
+
118120
If `time_series`, each backing index has an `index.mode` index setting of
119121
`time_series`.
120-
====
122+
=====
121123

122124
`index_patterns`::
123125
(Required, array of strings)
@@ -146,7 +148,7 @@ Template to be applied. It may optionally include an `aliases`, `mappings`, or
146148
+
147149
.Properties of `template`
148150
[%collapsible%open]
149-
====
151+
=====
150152
`aliases`::
151153
(Optional, object of objects) Aliases to add.
152154
+
@@ -161,7 +163,7 @@ include::{es-ref-dir}/indices/create-index.asciidoc[tag=aliases-props]
161163
include::{docdir}/rest-api/common-parms.asciidoc[tag=mappings]
162164
163165
include::{docdir}/rest-api/common-parms.asciidoc[tag=settings]
164-
====
166+
=====
165167

166168
`version`::
167169
(Optional, integer)
@@ -174,6 +176,7 @@ Marks this index template as deprecated.
174176
When creating or updating a non-deprecated index template that uses deprecated components,
175177
{es} will emit a deprecation warning.
176178
// end::index-template-api-body[]
179+
// end::request-body[]
177180

178181
[[put-index-template-api-example]]
179182
==== {api-examples-title}

docs/reference/ingest/apis/simulate-ingest.asciidoc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,21 @@ POST /_ingest/_simulate
102102
}
103103
}
104104
}
105+
},
106+
"index_template_substitutions": { <3>
107+
"my-index-template": {
108+
"index_patterns": ["my-index-*"],
109+
"composed_of": ["component_template_1", "component_template_2"]
110+
}
105111
}
106112
}
107113
----
108114

109115
<1> This replaces the existing `my-pipeline` pipeline with the contents given here for the duration of this request.
110116
<2> This replaces the existing `my-component-template` component template with the contents given here for the duration of this request.
111117
These templates can be used to change the pipeline(s) used, or to modify the mapping that will be used to validate the result.
118+
<3> This replaces the existing `my-index-template` index template with the contents given here for the duration of this request.
119+
These templates can be used to change the pipeline(s) used, or to modify the mapping that will be used to validate the result.
112120

113121
[[simulate-ingest-api-request]]
114122
==== {api-request-title}
@@ -225,6 +233,19 @@ include::{es-ref-dir}/indices/put-component-template.asciidoc[tag=template]
225233
226234
====
227235

236+
`index_template_substitutions`::
237+
(Optional, map of strings to objects)
238+
Map of index template names to substitute index template definition objects.
239+
+
240+
.Properties of index template definition objects
241+
[%collapsible%open]
242+
243+
====
244+
245+
include::{es-ref-dir}/indices/put-index-template.asciidoc[tag=request-body]
246+
247+
====
248+
228249
[[simulate-ingest-api-example]]
229250
==== {api-examples-title}
230251

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/Database.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,19 @@ enum Database {
169169
Property.TYPE
170170
),
171171
Set.of(Property.IP, Property.ASN, Property.ORGANIZATION_NAME, Property.NETWORK)
172-
);
172+
),
173+
CityV2(
174+
Set.of(
175+
Property.IP,
176+
Property.COUNTRY_ISO_CODE,
177+
Property.REGION_NAME,
178+
Property.CITY_NAME,
179+
Property.TIMEZONE,
180+
Property.LOCATION,
181+
Property.POSTAL_CODE
182+
),
183+
Set.of(Property.COUNTRY_ISO_CODE, Property.REGION_NAME, Property.CITY_NAME, Property.LOCATION)
184+
),;
173185

174186
private final Set<Property> properties;
175187
private final Set<Property> defaultProperties;

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IpinfoIpDataLookups.java

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ static Long parseAsn(final String asn) {
5858
}
5959
}
6060

61+
/**
62+
* Lax-ly parses a string that contains a double into a Double (or null, if such parsing isn't possible).
63+
* @param latlon a potentially empty (or null) string that is expected to contain a parsable double
64+
* @return the parsed double
65+
*/
66+
static Double parseLocationDouble(final String latlon) {
67+
if (latlon == null || Strings.hasText(latlon) == false) {
68+
return null;
69+
} else {
70+
String stripped = latlon.trim();
71+
try {
72+
return Double.parseDouble(stripped);
73+
} catch (NumberFormatException e) {
74+
logger.trace("Unable to parse non-compliant location string [{}]", latlon);
75+
return null;
76+
}
77+
}
78+
}
79+
6180
public record AsnResult(
6281
Long asn,
6382
@Nullable String country, // not present in the free asn database
@@ -88,6 +107,31 @@ public record CountryResult(
88107
public CountryResult {}
89108
}
90109

110+
public record GeolocationResult(
111+
String city,
112+
String country,
113+
Double latitude,
114+
Double longitude,
115+
String postalCode,
116+
String region,
117+
String timezone
118+
) {
119+
@SuppressWarnings("checkstyle:RedundantModifier")
120+
@MaxMindDbConstructor
121+
public GeolocationResult(
122+
@MaxMindDbParameter(name = "city") String city,
123+
@MaxMindDbParameter(name = "country") String country,
124+
@MaxMindDbParameter(name = "latitude") String latitude,
125+
@MaxMindDbParameter(name = "longitude") String longitude,
126+
// @MaxMindDbParameter(name = "network") String network, // for now we're not exposing this
127+
@MaxMindDbParameter(name = "postal_code") String postalCode,
128+
@MaxMindDbParameter(name = "region") String region,
129+
@MaxMindDbParameter(name = "timezone") String timezone
130+
) {
131+
this(city, country, parseLocationDouble(latitude), parseLocationDouble(longitude), postalCode, region, timezone);
132+
}
133+
}
134+
91135
static class Asn extends AbstractBase<AsnResult> {
92136
Asn(Set<Database.Property> properties) {
93137
super(properties, AsnResult.class);
@@ -183,6 +227,65 @@ protected Map<String, Object> transform(final Result<CountryResult> result) {
183227
}
184228
}
185229

230+
static class Geolocation extends AbstractBase<GeolocationResult> {
231+
Geolocation(final Set<Database.Property> properties) {
232+
super(properties, GeolocationResult.class);
233+
}
234+
235+
@Override
236+
protected Map<String, Object> transform(final Result<GeolocationResult> result) {
237+
GeolocationResult response = result.result;
238+
239+
Map<String, Object> data = new HashMap<>();
240+
for (Database.Property property : this.properties) {
241+
switch (property) {
242+
case IP -> data.put("ip", result.ip);
243+
case COUNTRY_ISO_CODE -> {
244+
String countryIsoCode = response.country;
245+
if (countryIsoCode != null) {
246+
data.put("country_iso_code", countryIsoCode);
247+
}
248+
}
249+
case REGION_NAME -> {
250+
String subdivisionName = response.region;
251+
if (subdivisionName != null) {
252+
data.put("region_name", subdivisionName);
253+
}
254+
}
255+
case CITY_NAME -> {
256+
String cityName = response.city;
257+
if (cityName != null) {
258+
data.put("city_name", cityName);
259+
}
260+
}
261+
case TIMEZONE -> {
262+
String locationTimeZone = response.timezone;
263+
if (locationTimeZone != null) {
264+
data.put("timezone", locationTimeZone);
265+
}
266+
}
267+
case POSTAL_CODE -> {
268+
String postalCode = response.postalCode;
269+
if (postalCode != null) {
270+
data.put("postal_code", postalCode);
271+
}
272+
}
273+
case LOCATION -> {
274+
Double latitude = response.latitude;
275+
Double longitude = response.longitude;
276+
if (latitude != null && longitude != null) {
277+
Map<String, Object> locationObject = new HashMap<>();
278+
locationObject.put("lat", latitude);
279+
locationObject.put("lon", longitude);
280+
data.put("location", locationObject);
281+
}
282+
}
283+
}
284+
}
285+
return data;
286+
}
287+
}
288+
186289
/**
187290
* Just a little record holder -- there's the data that we receive via the binding to our record objects from the Reader via the
188291
* getRecord call, but then we also need to capture the passed-in ip address that came from the caller as well as the network for

0 commit comments

Comments
 (0)