Skip to content

Commit f6570a3

Browse files
committed
Add support for GeoDistanceQuery's ignore_unmapped property
Signed-off-by: Thomas Farr <[email protected]>
1 parent 33245f6 commit f6570a3

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
33

44
## [Unreleased 2.x]
55
### Added
6+
- Added support for `GeoDistanceQuery`'s `ignore_unmapped` property ([#1430](https://github.com/opensearch-project/opensearch-java/pull/1430))
67

78
### Dependencies
89
- Bump `commons-logging:commons-logging` from 1.3.4 to 1.3.5 ([#1418](https://github.com/opensearch-project/opensearch-java/pull/1418))

java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQuery.java

+34-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public class GeoDistanceQuery extends QueryBase implements QueryVariant {
6262
@Nullable
6363
private final GeoValidationMethod validationMethod;
6464

65+
@Nullable
66+
private final Boolean ignoreUnmapped;
67+
6568
// ---------------------------------------------------------------------------------------------
6669

6770
private GeoDistanceQuery(Builder builder) {
@@ -72,7 +75,7 @@ private GeoDistanceQuery(Builder builder) {
7275
this.distance = builder.distance;
7376
this.distanceType = builder.distanceType;
7477
this.validationMethod = builder.validationMethod;
75-
78+
this.ignoreUnmapped = builder.ignoreUnmapped;
7679
}
7780

7881
public static GeoDistanceQuery of(Function<Builder, ObjectBuilder<GeoDistanceQuery>> fn) {
@@ -125,6 +128,14 @@ public final GeoValidationMethod validationMethod() {
125128
return this.validationMethod;
126129
}
127130

131+
/**
132+
* API name: {@code ignore_unmapped}
133+
*/
134+
@Nullable
135+
public final Boolean ignoreUnmapped() {
136+
return this.ignoreUnmapped;
137+
}
138+
128139
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
129140
generator.writeKey(this.field);
130141
this.location.serialize(generator, mapper);
@@ -144,10 +155,19 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
144155
this.validationMethod.serialize(generator, mapper);
145156
}
146157

158+
if (this.ignoreUnmapped != null) {
159+
generator.writeKey("ignore_unmapped");
160+
generator.write(this.ignoreUnmapped);
161+
}
147162
}
148163

149164
public Builder toBuilder() {
150-
return toBuilder(new Builder()).field(field).location(location);
165+
return toBuilder(new Builder()).field(field)
166+
.location(location)
167+
.distance(distance)
168+
.distanceType(distanceType)
169+
.validationMethod(validationMethod)
170+
.ignoreUnmapped(ignoreUnmapped);
151171
}
152172

153173
// ---------------------------------------------------------------------------------------------
@@ -193,6 +213,9 @@ public final Builder location(Function<GeoLocation.Builder, ObjectBuilder<GeoLoc
193213
@Nullable
194214
private GeoValidationMethod validationMethod;
195215

216+
@Nullable
217+
private Boolean ignoreUnmapped;
218+
196219
/**
197220
* API name: {@code distance}
198221
*/
@@ -217,6 +240,14 @@ public final Builder validationMethod(@Nullable GeoValidationMethod value) {
217240
return this;
218241
}
219242

243+
/**
244+
* API name: {@code ignore_unmapped}
245+
*/
246+
public final Builder ignoreUnmapped(@Nullable Boolean value) {
247+
this.ignoreUnmapped = value;
248+
return this;
249+
}
250+
220251
@Override
221252
protected Builder self() {
222253
return this;
@@ -250,6 +281,7 @@ protected static void setupGeoDistanceQueryDeserializer(ObjectDeserializer<GeoDi
250281
op.add(Builder::distance, JsonpDeserializer.stringDeserializer(), "distance");
251282
op.add(Builder::distanceType, GeoDistanceType._DESERIALIZER, "distance_type");
252283
op.add(Builder::validationMethod, GeoValidationMethod._DESERIALIZER, "validation_method");
284+
op.add(Builder::ignoreUnmapped, JsonpDeserializer.booleanDeserializer(), "ignore_unmapped");
253285

254286
op.setUnknownFieldHandler((builder, name, parser, mapper) -> {
255287
builder.field(name);

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQueryTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.util.Collections;
1212
import org.junit.Test;
13+
import org.opensearch.client.opensearch._types.GeoDistanceType;
1314
import org.opensearch.client.opensearch._types.GeoLocation;
1415
import org.opensearch.client.opensearch.model.ModelTestCase;
1516

@@ -18,6 +19,9 @@ public class GeoDistanceQueryTest extends ModelTestCase {
1819
public void toBuilder() {
1920
GeoDistanceQuery origin = new GeoDistanceQuery.Builder().field("field")
2021
.location(new GeoLocation.Builder().coords(Collections.singletonList(1.0)).build())
22+
.distance("1m")
23+
.distanceType(GeoDistanceType.Arc)
24+
.ignoreUnmapped(true)
2125
.build();
2226
GeoDistanceQuery copied = origin.toBuilder().build();
2327

0 commit comments

Comments
 (0)