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

Add support for phase_took & search_pipeline request params #1036

Merged
merged 1 commit into from
Jul 3, 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 @@ -11,6 +11,7 @@ This section is for maintaining a changelog for all breaking changes for the cli

### Added
- Document HTTP/2 support ([#330](https://github.com/opensearch-project/opensearch-java/pull/330))
- Add support for phase_took & search_pipeline request params ([#1036](https://github.com/opensearch-project/opensearch-java/pull/1036))

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public class SearchRequest extends RequestBase implements JsonpSerializable {
@Nullable
private final Boolean ccsMinimizeRoundtrips;

@Nullable
private final Boolean phaseTook;

@Nullable
private final String pipeline;

@Nullable
private final FieldCollapse collapse;

Expand Down Expand Up @@ -239,6 +245,8 @@ private SearchRequest(Builder builder) {
this.analyzer = builder.analyzer;
this.batchedReduceSize = builder.batchedReduceSize;
this.ccsMinimizeRoundtrips = builder.ccsMinimizeRoundtrips;
this.phaseTook = builder.phaseTook;
this.pipeline = builder.pipeline;
this.collapse = builder.collapse;
this.defaultOperator = builder.defaultOperator;
this.df = builder.df;
Expand Down Expand Up @@ -377,6 +385,27 @@ public final Boolean ccsMinimizeRoundtrips() {
return this.ccsMinimizeRoundtrips;
}

/**
* Indicates whether search phase took times should be returned
* in SearchResponse
* <p>
* API name: {@code phase_took}
*/
@Nullable
public final Boolean phaseTook() {
return this.phaseTook;
}

/**
* Specifies search pipeline name
* <p>
* API name: {@code pipeline}
*/
@Nullable
public final String pipeline() {
return this.pipeline;
}

/**
* API name: {@code collapse}
*/
Expand Down Expand Up @@ -1084,6 +1113,8 @@ public Builder toBuilder() {
.analyzer(analyzer)
.batchedReduceSize(batchedReduceSize)
.ccsMinimizeRoundtrips(ccsMinimizeRoundtrips)
.phaseTook(phaseTook)
.pipeline(pipeline)
.collapse(collapse)
.defaultOperator(defaultOperator)
.df(df)
Expand Down Expand Up @@ -1162,6 +1193,12 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<S
@Nullable
private Boolean ccsMinimizeRoundtrips;

@Nullable
private Boolean phaseTook;

@Nullable
private String pipeline;

@Nullable
private FieldCollapse collapse;

Expand Down Expand Up @@ -1415,6 +1452,27 @@ public final Builder ccsMinimizeRoundtrips(@Nullable Boolean value) {
return this;
}

/**
* Indicates whether search phase took times should be returned
* in SearchResponse
* <p>
* API name: {@code phase_took}
*/
public final Builder phaseTook(@Nullable Boolean value) {
this.phaseTook = value;
return this;
}

/**
* Specifies search pipeline name
* <p>
* API name: {@code pipeline}
*/
public final Builder pipeline(@Nullable String value) {
this.pipeline = value;
return this;
}

/**
* API name: {@code collapse}
*/
Expand Down Expand Up @@ -2354,6 +2412,12 @@ protected static void setupSearchRequestDeserializer(ObjectDeserializer<SearchRe
if (request.ccsMinimizeRoundtrips != null) {
params.put("ccs_minimize_roundtrips", String.valueOf(request.ccsMinimizeRoundtrips));
}
if (request.phaseTook != null) {
params.put("phase_took", String.valueOf(request.phaseTook));
}
if (request.pipeline != null) {
params.put("search_pipeline", request.pipeline);
}
if (request.q != null) {
params.put("q", request.q);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public class SearchTemplateRequest extends RequestBase implements JsonpSerializa
@Nullable
private final Boolean ccsMinimizeRoundtrips;

@Nullable
private final Boolean phaseTook;

@Nullable
private final String pipeline;

private final List<ExpandWildcard> expandWildcards;

@Nullable
Expand Down Expand Up @@ -113,6 +119,8 @@ private SearchTemplateRequest(Builder builder) {

this.allowNoIndices = builder.allowNoIndices;
this.ccsMinimizeRoundtrips = builder.ccsMinimizeRoundtrips;
this.phaseTook = builder.phaseTook;
this.pipeline = builder.pipeline;
this.expandWildcards = ApiTypeHelper.unmodifiable(builder.expandWildcards);
this.explain = builder.explain;
this.id = builder.id;
Expand Down Expand Up @@ -156,6 +164,27 @@ public final Boolean ccsMinimizeRoundtrips() {
return this.ccsMinimizeRoundtrips;
}

/**
* Indicates whether search phase took times should be returned
* in SearchResponse
* <p>
* API name: {@code phase_took}
*/
@Nullable
public final Boolean phaseTook() {
return this.phaseTook;
}

/**
* Specifies search pipeline name
* <p>
* API name: {@code pipeline}
*/
@Nullable
public final String pipeline() {
return this.pipeline;
}

/**
* Whether to expand wildcard expression to concrete indices that are open,
* closed or both.
Expand Down Expand Up @@ -334,6 +363,8 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
public Builder toBuilder() {
return new Builder().allowNoIndices(allowNoIndices)
.ccsMinimizeRoundtrips(ccsMinimizeRoundtrips)
.phaseTook(phaseTook)
.pipeline(pipeline)
.expandWildcards(expandWildcards)
.explain(explain)
.id(id)
Expand Down Expand Up @@ -362,6 +393,12 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<S
@Nullable
private Boolean ccsMinimizeRoundtrips;

@Nullable
private Boolean phaseTook;

@Nullable
private String pipeline;

@Nullable
private List<ExpandWildcard> expandWildcards;

Expand Down Expand Up @@ -424,6 +461,27 @@ public final Builder ccsMinimizeRoundtrips(@Nullable Boolean value) {
return this;
}

/**
* Indicates whether search phase took times should be returned
* in SearchResponse
* <p>
* API name: {@code phase_took}
*/
public final Builder phaseTook(@Nullable Boolean value) {
this.phaseTook = value;
return this;
}

/**
* Specifies search pipeline name
* <p>
* API name: {@code pipeline}
*/
public final Builder pipeline(@Nullable String value) {
this.pipeline = value;
return this;
}

/**
* Whether to expand wildcard expression to concrete indices that are open,
* closed or both.
Expand Down Expand Up @@ -700,6 +758,12 @@ protected static void setupSearchTemplateRequestDeserializer(ObjectDeserializer<
if (request.ccsMinimizeRoundtrips != null) {
params.put("ccs_minimize_roundtrips", String.valueOf(request.ccsMinimizeRoundtrips));
}
if (request.phaseTook != null) {
params.put("phase_took", String.valueOf(request.phaseTook));
}
if (request.pipeline != null) {
params.put("search_pipeline", request.pipeline);
}
if (request.routing != null) {
params.put("routing", request.routing);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ public void ext() {
assertEquals("{\"ext\":{\"similarity\":{\"fields\":[\"name\"]}}}", toJson(request));
}

@Test
public void phaseTook() {
SearchRequest request = new SearchRequest.Builder().phaseTook(true).build();

assertEquals("{}", toJson(request));
Copy link
Member

@dblock dblock Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't phase_took appear somewhere in the JSON?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phase_took and pipeline are query parameters whereas search_after and ext are in the request body. I think that's what toJson is testing

assertEquals(true, request.phaseTook());
assertTrue(Boolean.parseBoolean(SearchRequest._ENDPOINT.queryParameters(request).get("phase_took")));
}

@Test
public void pipeline() {
SearchRequest request = new SearchRequest.Builder().pipeline("my_pipeline").build();

assertEquals("{}", toJson(request));
assertEquals("my_pipeline", request.pipeline());
assertEquals("my_pipeline", SearchRequest._ENDPOINT.queryParameters(request).get("search_pipeline"));
}

@Test
public void toBuilder() {
SearchRequest origin = new SearchRequest.Builder().index("index").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,28 @@

package org.opensearch.client.opensearch.core;

import org.junit.Assert;
import org.junit.Test;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class SearchTemplateRequestTest extends Assert {
public class SearchTemplateRequestTest extends ModelTestCase {

@Test
public void phaseTook() {
SearchTemplateRequest request = new SearchTemplateRequest.Builder().phaseTook(true).build();

assertEquals("{}", toJson(request));
assertEquals(true, request.phaseTook());
assertTrue(Boolean.parseBoolean(SearchTemplateRequest._ENDPOINT.queryParameters(request).get("phase_took")));
}

@Test
public void pipeline() {
SearchTemplateRequest request = new SearchTemplateRequest.Builder().pipeline("my_pipeline").build();

assertEquals("{}", toJson(request));
assertEquals("my_pipeline", request.pipeline());
assertEquals("my_pipeline", SearchTemplateRequest._ENDPOINT.queryParameters(request).get("search_pipeline"));
}

@Test
public void toBuilder() {
Expand Down
Loading