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

[Backport 2.x] Switch type of expandNested from boolean to Boolean #2336

Merged
merged 1 commit into from
Dec 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static class CreateQueryRequest {
private QueryBuilder filter;
private QueryShardContext context;
private RescoreContext rescoreContext;
private boolean expandNested;
private Boolean expandNested;

public Optional<QueryBuilder> getFilter() {
return Optional.ofNullable(filter);
Expand All @@ -63,6 +63,10 @@ public Optional<QueryShardContext> getContext() {
public Optional<RescoreContext> getRescoreContext() {
return Optional.ofNullable(rescoreContext);
}

public Optional<Boolean> getExpandNested() {
return Optional.ofNullable(expandNested);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class KNNQueryBuilder extends AbstractQueryBuilder<KNNQueryBuilder> {
@Getter
private RescoreContext rescoreContext;
@Getter
private boolean expandNested;
private Boolean expandNested;

/**
* Constructs a new query with the given field name and vector
Expand Down Expand Up @@ -151,7 +151,7 @@ public static class Builder {
private String queryName;
private float boost = DEFAULT_BOOST;
private RescoreContext rescoreContext;
private boolean expandNested;
private Boolean expandNested;

public Builder() {}

Expand Down Expand Up @@ -210,7 +210,7 @@ public Builder rescoreContext(RescoreContext rescoreContext) {
return this;
}

public Builder expandNested(boolean expandNested) {
public Builder expandNested(Boolean expandNested) {
this.expandNested = expandNested;
return this;
}
Expand Down Expand Up @@ -330,7 +330,7 @@ public KNNQueryBuilder(String fieldName, float[] vector, int k, QueryBuilder fil
this.maxDistance = null;
this.minScore = null;
this.rescoreContext = null;
this.expandNested = false;
this.expandNested = null;
}

public static void initialize(ModelDao modelDao) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static Query create(CreateQueryRequest createQueryRequest) {
final Map<String, ?> methodParameters = createQueryRequest.getMethodParameters();
final RescoreContext rescoreContext = createQueryRequest.getRescoreContext().orElse(null);
final KNNEngine knnEngine = createQueryRequest.getKnnEngine();
final boolean expandNested = createQueryRequest.isExpandNested();
final boolean expandNested = createQueryRequest.getExpandNested().orElse(false);
BitSetProducer parentFilter = null;
if (createQueryRequest.getContext().isPresent()) {
QueryShardContext context = createQueryRequest.getContext().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static KNNQueryBuilder.Builder streamInput(StreamInput in, Function<Strin
}

if (minClusterVersionCheck.apply(EXPAND_NESTED)) {
builder.expandNested(in.readBoolean());
builder.expandNested(in.readOptionalBoolean());
}

return builder;
Expand Down Expand Up @@ -176,7 +176,7 @@ public static void streamOutput(StreamOutput out, KNNQueryBuilder builder, Funct
RescoreParser.streamOutput(out, builder.getRescoreContext());
}
if (minClusterVersionCheck.apply(EXPAND_NESTED)) {
out.writeBoolean(builder.isExpandNested());
out.writeOptionalBoolean(builder.getExpandNested());
}
}

Expand Down Expand Up @@ -252,8 +252,8 @@ public static void toXContent(XContentBuilder builder, ToXContent.Params params,
if (knnQueryBuilder.queryName() != null) {
builder.field(NAME_FIELD.getPreferredName(), knnQueryBuilder.queryName());
}
if (knnQueryBuilder.isExpandNested()) {
builder.field(EXPAND_NESTED, knnQueryBuilder.isExpandNested());
if (knnQueryBuilder.getExpandNested() != null) {
builder.field(EXPAND_NESTED, knnQueryBuilder.getExpandNested());
}

builder.endObject();
Expand Down
Loading