Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding WithFieldName interface for QueryBuilders with fieldName #15705

Merged
merged 3 commits into from
Sep 5, 2024
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 @@ -52,6 +52,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add canRemain method to TargetPoolAllocationDecider to move shards from local to remote pool for hot to warm tiering ([#15010](https://github.com/opensearch-project/OpenSearch/pull/15010))
- ClusterManagerTaskThrottler Improvements ([#15508](https://github.com/opensearch-project/OpenSearch/pull/15508))
- Reset DiscoveryNodes in all transport node actions request ([#15131](https://github.com/opensearch-project/OpenSearch/pull/15131))
- Adding WithFieldName interface for QueryBuilders with fieldName ([#15705](https://github.com/opensearch-project/OpenSearch/pull/15705))
- Relax the join validation for Remote State publication ([#15471](https://github.com/opensearch-project/OpenSearch/pull/15471))
- MultiTermQueries in keyword fields now default to `indexed` approach and gated behind cluster setting ([#15637](https://github.com/opensearch-project/OpenSearch/pull/15637))
- Making _cat/allocation API use indexLevelStats ([#15292](https://github.com/opensearch-project/OpenSearch/pull/15292))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.opensearch.index.query.AbstractQueryBuilder;
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.index.query.WithFieldName;
import org.opensearch.plugin.correlation.core.index.mapper.VectorFieldMapper;

import java.io.IOException;
Expand All @@ -36,7 +37,7 @@
*
* @opensearch.internal
*/
public class CorrelationQueryBuilder extends AbstractQueryBuilder<CorrelationQueryBuilder> {
public class CorrelationQueryBuilder extends AbstractQueryBuilder<CorrelationQueryBuilder> implements WithFieldName {

private static final Logger log = LogManager.getLogger(CorrelationQueryBuilder.class);
protected static final ParseField VECTOR_FIELD = new ParseField("vector");
Expand Down Expand Up @@ -205,6 +206,7 @@ public void setFieldName(String fieldName) {
* get field name
* @return field name
*/
@Override
public String fieldName() {
return fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
*
* @opensearch.internal
*/
public abstract class AbstractGeometryQueryBuilder<QB extends AbstractGeometryQueryBuilder<QB>> extends AbstractQueryBuilder<QB> {
public abstract class AbstractGeometryQueryBuilder<QB extends AbstractGeometryQueryBuilder<QB>> extends AbstractQueryBuilder<QB>
implements
WithFieldName {

public static final String DEFAULT_SHAPE_INDEX_NAME = "shapes";
public static final String DEFAULT_SHAPE_FIELD_NAME = "shape";
Expand Down Expand Up @@ -218,6 +220,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
/**
* @return the name of the field that will be queried
*/
@Override
public String fieldName() {
return fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*
* @opensearch.internal
*/
public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>> extends AbstractQueryBuilder<QB> {
public abstract class BaseTermQueryBuilder<QB extends BaseTermQueryBuilder<QB>> extends AbstractQueryBuilder<QB> implements WithFieldName {

public static final ParseField VALUE_FIELD = new ParseField("value");

Expand Down Expand Up @@ -153,6 +153,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
}

/** Returns the field name used in this query. */
@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
* @opensearch.internal
*/
@Deprecated
public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQueryBuilder> {
public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQueryBuilder> implements WithFieldName {

public static final String COMMON_TERMS_QUERY_DEPRECATION_MSG = "[match] query which can efficiently "
+ "skip blocks of documents if the total number of hits is not tracked";
Expand Down Expand Up @@ -152,6 +152,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeFloat(cutoffFrequency);
}

@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
*
* @opensearch.internal
*/
public class DistanceFeatureQueryBuilder extends AbstractQueryBuilder<DistanceFeatureQueryBuilder> {
public class DistanceFeatureQueryBuilder extends AbstractQueryBuilder<DistanceFeatureQueryBuilder> implements WithFieldName {
public static final String NAME = "distance_feature";

private static final ParseField FIELD_FIELD = new ParseField("field");
Expand Down Expand Up @@ -136,7 +136,8 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
return fieldType.distanceFeatureQuery(origin.origin(), pivot, 1.0f, context);
}

String fieldName() {
@Override
public String fieldName() {
return field;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
*
* @opensearch.internal
*/
public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder> {
public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder> implements WithFieldName {
public static final String NAME = "exists";

public static final ParseField FIELD_FIELD = new ParseField("field");
Expand Down Expand Up @@ -89,6 +89,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
/**
* @return the field name that has to exist for this query to match
*/
@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
*
* @opensearch.internal
*/
public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMaskingSpanQueryBuilder> implements SpanQueryBuilder {
public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMaskingSpanQueryBuilder>
implements
SpanQueryBuilder,
WithFieldName {

public static final String NAME = "span_field_masking";
public static final ParseField SPAN_FIELD_MASKING_FIELD = new ParseField(NAME, "field_masking_span");
Expand Down Expand Up @@ -100,6 +103,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
/**
* @return the field name for this query
*/
@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
*
* @opensearch.internal
* */
public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBoundingBoxQueryBuilder> {
public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBoundingBoxQueryBuilder> implements WithFieldName {
public static final String NAME = "geo_bounding_box";

/** Default type for executing this query (memory as of this writing). */
Expand Down Expand Up @@ -263,6 +263,7 @@ public GeoExecType type() {
}

/** Returns the name of the field to base the bounding box computation on. */
@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
*
* @opensearch.internal
*/
public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQueryBuilder> {
public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQueryBuilder> implements WithFieldName {
public static final String NAME = "geo_distance";

/** Default for distance unit computation. */
Expand Down Expand Up @@ -129,6 +129,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
}

/** Name of the field this query is operating on. */
@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
*
* @opensearch.internal
*/
public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQueryBuilder> {
public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQueryBuilder> implements WithFieldName {
public static final String NAME = "geo_polygon";

/**
Expand Down Expand Up @@ -131,6 +131,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeBoolean(ignoreUnmapped);
}

@Override
public String fieldName() {
return fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
*
* @opensearch.internal
*/
public class MatchBoolPrefixQueryBuilder extends AbstractQueryBuilder<MatchBoolPrefixQueryBuilder> {
public class MatchBoolPrefixQueryBuilder extends AbstractQueryBuilder<MatchBoolPrefixQueryBuilder> implements WithFieldName {

public static final String NAME = "match_bool_prefix";

Expand Down Expand Up @@ -127,6 +127,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
}

/** Returns the field name used in this query. */
@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*
* @opensearch.internal
*/
public class MatchPhrasePrefixQueryBuilder extends AbstractQueryBuilder<MatchPhrasePrefixQueryBuilder> {
public class MatchPhrasePrefixQueryBuilder extends AbstractQueryBuilder<MatchPhrasePrefixQueryBuilder> implements WithFieldName {
public static final String NAME = "match_phrase_prefix";
public static final ParseField MAX_EXPANSIONS_FIELD = new ParseField("max_expansions");
public static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query");
Expand Down Expand Up @@ -104,6 +104,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
}

/** Returns the field name used in this query. */
@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*
* @opensearch.internal
*/
public class MatchPhraseQueryBuilder extends AbstractQueryBuilder<MatchPhraseQueryBuilder> {
public class MatchPhraseQueryBuilder extends AbstractQueryBuilder<MatchPhraseQueryBuilder> implements WithFieldName {
public static final String NAME = "match_phrase";
public static final ParseField SLOP_FIELD = new ParseField("slop");
public static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query");
Expand Down Expand Up @@ -100,6 +100,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
}

/** Returns the field name used in this query. */
@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
*
* @opensearch.internal
*/
public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> implements WithFieldName {

private static final String CUTOFF_FREQUENCY_DEPRECATION_MSG = "you can omit this option, "
+ "the [match] query can skip block of documents efficiently if the total number of hits is not tracked";
Expand Down Expand Up @@ -171,6 +171,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
}

/** Returns the field name used in this query. */
@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,4 @@
*
* @opensearch.internal
*/
public interface MultiTermQueryBuilder extends QueryBuilder {
/**
* Get the field name for this query.
*/
String fieldName();
}
public interface MultiTermQueryBuilder extends QueryBuilder, WithFieldName {}
jainankitk marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void visit(QueryBuilderVisitor visitor) {
*
* @opensearch.internal
*/
public static class SpanGapQueryBuilder implements SpanQueryBuilder {
public static class SpanGapQueryBuilder implements SpanQueryBuilder, WithFieldName {
public static final String NAME = "span_gap";

/** Name of field to match against. */
Expand Down Expand Up @@ -358,6 +358,7 @@ public SpanGapQueryBuilder(StreamInput in) throws IOException {
/**
* @return fieldName The name of the field
*/
@Override
public String fieldName() {
return fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
*
* @opensearch.internal
*/
public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> {
public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> implements WithFieldName {
public static final String NAME = "terms";

private final String fieldName;
Expand Down Expand Up @@ -269,6 +269,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
}
}

@Override
public String fieldName() {
return this.fieldName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.index.query;

/**
* Interface for classes with a fieldName method
*
* @opensearch.internal
*/
public interface WithFieldName {
/**
* Get the field name for this query.
*/
String fieldName();
}
Loading