Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Bump `org.jsoup:jsoup` from 1.21.2 to 1.22.1 ([#20368](https://github.com/opensearch-project/OpenSearch/pull/20368))
- Bump `org.jline:jline` from 3.30.5 to 3.30.6 ([#20369](https://github.com/opensearch-project/OpenSearch/pull/20369))
- Bump `lycheeverse/lychee-action` from 2.6.1 to 2.7.0 ([#20370](https://github.com/opensearch-project/OpenSearch/pull/20370))
- Bump `opensearch-protobufs` from 1.0.0 to 1.1.0 and update transport-grpc module compatibility ([#20396](https://github.com/opensearch-project/OpenSearch/pull/20396))

### Removed

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kotlin = "1.7.10"
antlr4 = "4.13.1"
guava = "33.2.1-jre"
gson = "2.13.2"
opensearchprotobufs = "1.0.0"
opensearchprotobufs = "1.1.0"
protobuf = "3.25.8"
jakarta_annotation = "1.3.5"
google_http_client = "1.44.1"
Expand Down
1 change: 0 additions & 1 deletion modules/transport-grpc/licenses/protobufs-1.0.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions modules/transport-grpc/licenses/protobufs-1.1.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4d49daae7d84f850a876540ee7b6a979e769d4c7

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4d49daae7d84f850a876540ee7b6a979e769d4c7
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public static GeoPoint parseGeoPoint(
point.resetLat(latLon.getLat());
point.resetLon(latLon.getLon());

} else if (geoLocation.hasDoubleArray()) {
org.opensearch.protobufs.DoubleArray doubleArray = geoLocation.getDoubleArray();
} else if (geoLocation.hasCoords()) {
org.opensearch.protobufs.DoubleArray doubleArray = geoLocation.getCoords();
int count = doubleArray.getDoubleArrayCount();
if (count < 2) {
throw new IllegalArgumentException("[geo_point] field type should have at least two dimensions");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.index.query.TermsQueryBuilder;
import org.opensearch.indices.TermsLookup;
import org.opensearch.protobufs.TermsQueryField;
import org.opensearch.transport.grpc.proto.response.common.FieldValueProtoUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -73,48 +72,6 @@ static TermsQueryBuilder fromProto(org.opensearch.protobufs.TermsQuery termsQuer
return builder;
}

/**
* Converts a Protocol Buffer TermsQueryField to an OpenSearch TermQueryBuilder.
* This method handles the field-specific conversion (values or lookup) without
* boost, queryName, or valueType which are handled at the TermsQuery level.
*
* @param termsQueryProto The Protocol Buffer TermsQueryField object
* @return A configured TermQueryBuilder instance
* @throws IllegalArgumentException if the term query field value is not recognized
*/
static TermsQueryBuilder fromProto(TermsQueryField termsQueryProto) {
String fieldName = null;
List<Object> values = null;
TermsLookup termsLookup = null;

switch (termsQueryProto.getTermsQueryFieldCase()) {
case FIELD_VALUE_ARRAY:
values = parseFieldValueArray(termsQueryProto.getFieldValueArray());
break;
case LOOKUP:
termsLookup = parseTermsLookup(termsQueryProto.getLookup());
break;
case TERMSQUERYFIELD_NOT_SET:
default:
throw new IllegalArgumentException("Neither field_value_array nor lookup is set");
}

if (values == null && termsLookup == null) {
throw new IllegalArgumentException("Either field_value_array or lookup must be set");
}

TermsQueryBuilder termsQueryBuilder;
if (values == null) {
termsQueryBuilder = new TermsQueryBuilder(fieldName, termsLookup);
} else if (termsLookup == null) {
termsQueryBuilder = new TermsQueryBuilder(fieldName, values);
} else {
throw new IllegalArgumentException("values and termsLookup cannot both be null");
}

return termsQueryBuilder;
}

/**
* Builds a TermsQueryBuilder from a field name, TermsQueryField oneof, and value_type.
* @param fieldName the field name (from the terms map key)
Expand All @@ -136,15 +93,15 @@ static TermsQueryBuilder fromProto(
TermsLookup termsLookup = null;

switch (termsQueryField.getTermsQueryFieldCase()) {
case FIELD_VALUE_ARRAY:
values = parseFieldValueArray(termsQueryField.getFieldValueArray());
case VALUE:
values = parseFieldValueArray(termsQueryField.getValue());
break;
case LOOKUP:
termsLookup = parseTermsLookup(termsQueryField.getLookup());
break;
case TERMSQUERYFIELD_NOT_SET:
default:
throw new IllegalArgumentException("Neither field_value_array nor lookup is set");
throw new IllegalArgumentException("Neither value nor lookup is set");
}

if (values == null && termsLookup == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.opensearch.common.document.DocumentField;
import org.opensearch.core.common.bytes.BytesArray;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.seqno.SequenceNumbers;
import org.opensearch.protobufs.InnerHitsResult;
Expand Down Expand Up @@ -261,15 +260,30 @@ private static void processMatchedQueries(SearchHit hit, org.opensearch.protobuf
// boolean includeMatchedQueriesScore = params.paramAsBoolean(RestSearchAction.INCLUDE_NAMED_QUERIES_SCORE_PARAM, false);
boolean includeMatchedQueriesScore = false;

org.opensearch.protobufs.HitMatchedQueries.Builder matchedQueriesBuilder = org.opensearch.protobufs.HitMatchedQueries
.newBuilder();
if (includeMatchedQueriesScore) {
// TODO map type is missing in spec
// for (Map.Entry<String, Float> entry : matchedQueries.entrySet()) {
// hitBuilder.putMatchedqueires(entry.getKey(), entry.getValue());
// TODO: uncomment when have a way to pass the param to the converter
// Map<String, Float> matchedQueriesWithScores = hit.getMatchedQueriesAndScores();
// org.opensearch.protobufs.DoubleMap.Builder doubleMapBuilder = org.opensearch.protobufs.DoubleMap.newBuilder();
// for (Map.Entry<String, Float> entry : matchedQueriesWithScores.entrySet()) {
// doubleMapBuilder.putDoubleMap(entry.getKey(), entry.getValue().doubleValue());
// }
// matchedQueriesBuilder.setScores(doubleMapBuilder.build());
} else {
org.opensearch.protobufs.StringArray.Builder namesBuilder = org.opensearch.protobufs.StringArray.newBuilder();
for (String matchedFilter : hit.getMatchedQueries()) {
namesBuilder.addStringArray(matchedFilter);
}
matchedQueriesBuilder.setNames(namesBuilder.build());

// Populate deprecated matched_queries field for backward compatibility with old clients
for (String matchedFilter : hit.getMatchedQueries()) {
hitBuilder.addMatchedQueries(matchedFilter);
}
}

hitBuilder.setMatchedQueries2(matchedQueriesBuilder.build());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void testParseGeoPointWithDoubleArrayTwoDimensions() {
.addDoubleArray(37.7749) // lat
.build();

GeoLocation geoLocation = GeoLocation.newBuilder().setDoubleArray(doubleArray).build();
GeoLocation geoLocation = GeoLocation.newBuilder().setCoords(doubleArray).build();

GeoPoint result = GeoPointProtoUtils.parseGeoPoint(geoLocation);

Expand All @@ -70,7 +70,7 @@ public void testParseGeoPointWithDoubleArrayThreeDimensions() {
.addDoubleArray(100.0) // z (elevation)
.build();

GeoLocation geoLocation = GeoLocation.newBuilder().setDoubleArray(doubleArray).build();
GeoLocation geoLocation = GeoLocation.newBuilder().setCoords(doubleArray).build();

// Test with ignoreZValue = true
GeoPoint point = new GeoPoint();
Expand All @@ -90,7 +90,7 @@ public void testParseGeoPointWithDoubleArrayThreeDimensionsNoIgnore() {
.addDoubleArray(0.0) // z (elevation)
.build();

GeoLocation geoLocation = GeoLocation.newBuilder().setDoubleArray(doubleArray).build();
GeoLocation geoLocation = GeoLocation.newBuilder().setCoords(doubleArray).build();

// Test with ignoreZValue = false and z = 0.0 (should throw OpenSearchParseException)
GeoPoint point = new GeoPoint();
Expand Down Expand Up @@ -163,7 +163,7 @@ public void testParseGeoPointWithDoubleArrayTooFewDimensions() {
.addDoubleArray(-122.4194) // Only lon, missing lat
.build();

GeoLocation geoLocation = GeoLocation.newBuilder().setDoubleArray(doubleArray).build();
GeoLocation geoLocation = GeoLocation.newBuilder().setCoords(doubleArray).build();

IllegalArgumentException exception = expectThrows(
IllegalArgumentException.class,
Expand All @@ -185,7 +185,7 @@ public void testParseGeoPointWithDoubleArrayTooManyDimensions() {
.addDoubleArray(200.0) // extra dimension
.build();

GeoLocation geoLocation = GeoLocation.newBuilder().setDoubleArray(doubleArray).build();
GeoLocation geoLocation = GeoLocation.newBuilder().setCoords(doubleArray).build();

IllegalArgumentException exception = expectThrows(
IllegalArgumentException.class,
Expand All @@ -206,7 +206,7 @@ public void testParseGeoPointWithDoubleArrayThreeDimensionsWithNonZeroZ() {
.addDoubleArray(100.0) // non-zero z (elevation)
.build();

GeoLocation geoLocation = GeoLocation.newBuilder().setDoubleArray(doubleArray).build();
GeoLocation geoLocation = GeoLocation.newBuilder().setCoords(doubleArray).build();

// Test with ignoreZValue = false and non-zero z (should throw OpenSearchParseException)
GeoPoint point = new GeoPoint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testFromProtoWithDoubleArrayGeoLocation() {
.addDoubleArray(40.7) // lat
.build();

GeoLocation geoLocation = GeoLocation.newBuilder().setDoubleArray(doubleArray).build();
GeoLocation geoLocation = GeoLocation.newBuilder().setCoords(doubleArray).build();

GeoDistanceQuery geoDistanceQuery = GeoDistanceQuery.newBuilder()
.setXName("location")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public void testGeoDistanceQueryConversionWithDoubleArray() {
.addDoubleArray(40.7589) // lat
.build();

GeoLocation geoLocation = GeoLocation.newBuilder().setDoubleArray(doubleArray).build();
GeoLocation geoLocation = GeoLocation.newBuilder().setCoords(doubleArray).build();

GeoDistanceQuery geoDistanceQuery = GeoDistanceQuery.newBuilder()
.setXName("location")
Expand Down Expand Up @@ -604,7 +604,7 @@ public void testTermsQueryConversion() {
FieldValue fv1 = FieldValue.newBuilder().setString("electronics").build();
FieldValue fv2 = FieldValue.newBuilder().setString("books").build();
FieldValueArray fva = FieldValueArray.newBuilder().addFieldValueArray(fv1).addFieldValueArray(fv2).build();
TermsQueryField termsQueryField = TermsQueryField.newBuilder().setFieldValueArray(fva).build();
TermsQueryField termsQueryField = TermsQueryField.newBuilder().setValue(fva).build();

QueryContainer queryContainer = QueryContainer.newBuilder()
.setTerms(org.opensearch.protobufs.TermsQuery.newBuilder().putTerms("category", termsQueryField).setBoost(1.5f).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testGetHandledQueryCase() {
public void testFromProto() {
org.opensearch.protobufs.FieldValue fv = org.opensearch.protobufs.FieldValue.newBuilder().setString("v1").build();
org.opensearch.protobufs.FieldValueArray fva = org.opensearch.protobufs.FieldValueArray.newBuilder().addFieldValueArray(fv).build();
TermsQueryField termsQueryField = TermsQueryField.newBuilder().setFieldValueArray(fva).build();
TermsQueryField termsQueryField = TermsQueryField.newBuilder().setValue(fva).build();
Map<String, TermsQueryField> termsMap = new HashMap<>();
termsMap.put("test-field", termsQueryField);
TermsQuery termsQuery = TermsQuery.newBuilder().putTerms("test-field", termsQueryField).build();
Expand Down Expand Up @@ -89,7 +89,7 @@ public void testFromProtoWithEmptyTermsMap() {
public void testFromProtoWithBoostAndQueryName() {
org.opensearch.protobufs.FieldValue fv = org.opensearch.protobufs.FieldValue.newBuilder().setString("test_value").build();
org.opensearch.protobufs.FieldValueArray fva = org.opensearch.protobufs.FieldValueArray.newBuilder().addFieldValueArray(fv).build();
TermsQueryField termsQueryField = TermsQueryField.newBuilder().setFieldValueArray(fva).build();
TermsQueryField termsQueryField = TermsQueryField.newBuilder().setValue(fva).build();

TermsQuery termsQuery = TermsQuery.newBuilder()
.putTerms("test_field", termsQueryField)
Expand All @@ -116,7 +116,7 @@ public void testFromProtoWithValueType() {
org.opensearch.protobufs.FieldValue fv = org.opensearch.protobufs.FieldValue.newBuilder().setString("AQI=").build(); // base64 for
// {1,2}
org.opensearch.protobufs.FieldValueArray fva = org.opensearch.protobufs.FieldValueArray.newBuilder().addFieldValueArray(fv).build();
TermsQueryField termsQueryField = TermsQueryField.newBuilder().setFieldValueArray(fva).build();
TermsQueryField termsQueryField = TermsQueryField.newBuilder().setValue(fva).build();

TermsQuery termsQuery = TermsQuery.newBuilder()
.putTerms("bitmap_field", termsQueryField)
Expand Down Expand Up @@ -174,7 +174,7 @@ public void testFromProtoWithTermsLookup() {
public void testFromProtoWithDefaultValues() {
org.opensearch.protobufs.FieldValue fv = org.opensearch.protobufs.FieldValue.newBuilder().setString("default_value").build();
org.opensearch.protobufs.FieldValueArray fva = org.opensearch.protobufs.FieldValueArray.newBuilder().addFieldValueArray(fv).build();
TermsQueryField termsQueryField = TermsQueryField.newBuilder().setFieldValueArray(fva).build();
TermsQueryField termsQueryField = TermsQueryField.newBuilder().setValue(fva).build();

TermsQuery termsQuery = TermsQuery.newBuilder().putTerms("default_field", termsQueryField).build();

Expand Down
Loading
Loading