Skip to content

Commit

Permalink
Add option to set headers and sort options in cat requests (opensearc…
Browse files Browse the repository at this point in the history
…h-project#412)

* Adding x-amz-content-sha256 header for signed requests (opensearch-project#339)

* Adding X-Amz-Content-Sha256 header for signed requests

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Adding CHANGELOG entry

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Adding documentation comment

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Adding tests

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Addressing comments

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Addressing comments

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Removing refresh policy for integ tests for Sigv4

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Updating the developer guide

Signed-off-by: Vacha Shah <vachshah@amazon.com>

Signed-off-by: Vacha Shah <vachshah@amazon.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Fix issue with completion suggester being parsed as term suggester. (opensearch-project#347)

* Fix issue with completion suggester being parsed as term suggester.

This commit fixes the issue where a completion suggester search request
was being parsed as a term suggester and failing due to "Missing
required property 'TermSuggestOption.score'"

This solution was originally proposed by Github user @apatrida

Signed-off-by: Dan Hart <git@danielhart.me>

* Remove commented code

Signed-off-by: Dan Hart <git@danielhart.me>

* Fix format of changelog item

Signed-off-by: Dan Hart <git@danielhart.me>

Signed-off-by: Dan Hart <git@danielhart.me>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Update USER_GUIDE to use exact AWS brand names (opensearch-project#352)

Minor update to use exact brand names. "OpenSearch" is rather overloaded
to I find it less confusing to be precise in the naming.

Signed-off-by: Andrew Ross <andrross@amazon.com>

Signed-off-by: Andrew Ross <andrross@amazon.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Bumps Jackson from 2.14.1 to 2.14.2 (opensearch-project#357)

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Bulk UpdateOperation misses upsert options (opensearch-project#353)

* Bulk UpdateOperation misses upsert options

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Fix formatting

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

---------

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Upgrading compatibility to opensearch 2.5 (opensearch-project#367)

* Upgrading compatibility to opensearch 2.5

Signed-off-by: amitai stern <123amitai@gmail.com>

* latest 2.4 version

Signed-off-by: amitai stern <123amitai@gmail.com>

* keep existing compatibility matrix rows, this pr adds a new row for versions of opensearch after 2.3.0

Signed-off-by: amitai stern <123amitai@gmail.com>

---------

Signed-off-by: amitai stern <123amitai@gmail.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* add option to set columns into cat indices request

Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* add changelog

Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* changes in CatRequestBase, IndicesRequest, NodesRequest, RecoveryRequest and add tests

Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Feature/range aggregation fix 369 (opensearch-project#370)

* test: create integration tests for date_range and range aggregation (opensearch-project#369)

Signed-off-by: Dominik Szczepanczyk <szczepanczyk.dominik@gmail.com>

* fix: add a missing key propery to the RangeBucket (opensearch-project#369)

Signed-off-by: Dominik Szczepanczyk <szczepanczyk.dominik@gmail.com>

* docs: add CHANGELOG entry (opensearch-project#369)

Signed-off-by: Dominik Szczepanczyk <szczepanczyk.dominik@gmail.com>

---------

Signed-off-by: Dominik Szczepanczyk <szczepanczyk.dominik@gmail.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Fixing integration tests (opensearch-project#375)

* Fixing integration tests

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Updating the test with a non-exact check

Signed-off-by: Vacha Shah <vachshah@amazon.com>

---------

Signed-off-by: Vacha Shah <vachshah@amazon.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Adding bulk request example in user guide (opensearch-project#373)

Signed-off-by: Vacha Shah <vachshah@amazon.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Fixing issue when tracktotalhits is disabled (opensearch-project#372)

* Fixing issue when tracktotalhits is disabled

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Update Changelog

Signed-off-by: Vacha Shah <vachshah@amazon.com>

---------

Signed-off-by: Vacha Shah <vachshah@amazon.com>
Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* changes changelog

Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Bump io.github.classgraph:classgraph from 4.8.154 to 4.8.156 (opensearch-project#390)

* Bump io.github.classgraph:classgraph from 4.8.154 to 4.8.156

Bumps [io.github.classgraph:classgraph](https://github.com/classgraph/classgraph) from 4.8.154 to 4.8.156.
- [Release notes](https://github.com/classgraph/classgraph/releases)
- [Commits](classgraph/classgraph@classgraph-4.8.154...classgraph-4.8.156)

---
updated-dependencies:
- dependency-name: io.github.classgraph:classgraph
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update changelog

Signed-off-by: dependabot[bot] <support@github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Add 2PR approval to release workflow (opensearch-project#383)

Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Adding an example to use raw JSON class instead of target classes (opensearch-project#385)

Signed-off-by: Vacha Shah <vachshah@amazon.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Update Gradle to 8.0.2 (opensearch-project#392)

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Add "mappings" field to IndexSettings object (opensearch-project#382)

Signed-off-by: Ilya Lukyanovich <l000kian@gmail.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Created untriaged issue workflow. (opensearch-project#364)

Signed-off-by: dblock <dblock@amazon.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Bump io.github.classgraph:classgraph from 4.8.156 to 4.8.157 in /java-client (opensearch-project#403)

* Bump io.github.classgraph:classgraph in /java-client

Bumps [io.github.classgraph:classgraph](https://github.com/classgraph/classgraph) from 4.8.156 to 4.8.157.
- [Release notes](https://github.com/classgraph/classgraph/releases)
- [Commits](classgraph/classgraph@classgraph-4.8.156...classgraph-4.8.157)

---
updated-dependencies:
- dependency-name: io.github.classgraph:classgraph
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update changelog

Signed-off-by: dependabot[bot] <support@github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Add buffered lookahead for Jackson (opensearch-project#338)

Signed-off-by: luneo7 <luneo7@gmail.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* Mask env values for snapshots (opensearch-project#411)

Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* option to set headers and sort into cat requests

Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* fix test

Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* fix changelog

Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

* add cat examples into USER_GUID

Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>

---------

Signed-off-by: Vacha Shah <vachshah@amazon.com>
Signed-off-by: MarinaRazumovsky <rzm.mrn@gmail.com>
Signed-off-by: Dan Hart <git@danielhart.me>
Signed-off-by: Andrew Ross <andrross@amazon.com>
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
Signed-off-by: amitai stern <123amitai@gmail.com>
Signed-off-by: Dominik Szczepanczyk <szczepanczyk.dominik@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
Signed-off-by: Ilya Lukyanovich <l000kian@gmail.com>
Signed-off-by: dblock <dblock@amazon.com>
Signed-off-by: luneo7 <luneo7@gmail.com>
Co-authored-by: Vacha Shah <vachshah@amazon.com>
Co-authored-by: Danny Hart <git@danielhart.me>
Co-authored-by: Andrew Ross <andrross@amazon.com>
Co-authored-by: Andriy Redko <andriy.redko@aiven.io>
Co-authored-by: amitai stern <123amitai@gmail.com>
Co-authored-by: szczepanczykd <48957041+szczepanczykd@users.noreply.github.com>
Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sayali Gaikawad <61760125+gaiksaya@users.noreply.github.com>
Co-authored-by: Ilya Lukyanovich <ilya.lukyanovich@dataart.com>
Co-authored-by: Lucas Rogerio Caetano Ferreira <luneo7@users.noreply.github.com>
  • Loading branch information
13 people authored Mar 21, 2023
1 parent b69a76a commit 938170a
Show file tree
Hide file tree
Showing 27 changed files with 1,153 additions and 801 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Require two maintainers to approve release ([#383](https://github.com/opensearch-project/opensearch-java/pull/383))
- Add support for mapping limit settings ([#382](https://github.com/opensearch-project/opensearch-java/pull/382))
- Add buffered lookahead for Jackson ([#338](https://github.com/opensearch-project/opensearch-java/pull/338))
- Add support for headers and sort parameters in cat requests ([#388](https://github.com/opensearch-project/opensearch-java/issues/388))

### Dependencies
- Bumps `classgraph` from 4.8.149 to 4.8.154
Expand Down
29 changes: 29 additions & 0 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
- [Aggregations](#aggregations)
- [Delete the document](#delete-the-document)
- [Delete the index](#delete-the-index)
- [Cat API](#cat-api)
- [Cat Indices](#cat-indices)
- [Cat Aliases](#cat-aliases)
- [Cat Nodes](#cat-nodes)
- [Using different transport options](#using-different-transport-options)
- [Amazon OpenSearch Service](#amazon-opensearch-service)

Expand Down Expand Up @@ -210,6 +214,31 @@ DeleteIndexRequest deleteIndexRequest = new DeleteRequest.Builder().index(index)
DeleteIndexResponse deleteIndexResponse = client.indices().delete(deleteIndexRequest);
```

## Cat API

### Cat Indices
The following sample code cat indices with required headers and sorted by creation date

```java
IndicesRequest indicesRequest = new IndicesRequest.Builder()
.headers("index,health,status,pri,rep,doc.count,creation.date,creation.date.string").sort("creation.date").build();
IndicesResponse indicesResponse = javaClient().cat().indices(indicesRequest);
```


### Cat aliases
The following sample code cat aliases with name "test-alias" and sorted by index
```java
AliasesRequest aliasesRequest = new AliasesRequest.Builder().name("test-alias").sort("index").build();
AliasesResponse aliasesResponse = javaClient().cat().aliases(aliasesRequest);
```

### Cat nodes
The following sample code cat nodes sorted by cpu
```java
NodesResponse nodesResponse = javaClient().cat().nodes(r -> r.sort("cpu"));
```

# Using different transport options

## Amazon OpenSearch Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@
import org.opensearch.client.transport.endpoints.SimpleEndpoint;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

// typedef: cat.aliases.Request

Expand All @@ -67,7 +66,7 @@ public class AliasesRequest extends CatRequestBase {
// ---------------------------------------------------------------------------------------------

private AliasesRequest(Builder builder) {

super(builder);
this.expandWildcards = ApiTypeHelper.unmodifiable(builder.expandWildcards);
this.name = ApiTypeHelper.unmodifiable(builder.name);

Expand Down Expand Up @@ -102,7 +101,7 @@ public final List<String> name() {
* Builder for {@link AliasesRequest}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<AliasesRequest> {
public static class Builder extends CatRequestBaseBuilder<AliasesRequest.Builder> {
@Nullable
private List<ExpandWildcard> expandWildcards;

Expand Down Expand Up @@ -170,6 +169,11 @@ public AliasesRequest build() {

return new AliasesRequest(this);
}

@Override
protected Builder self() {
return this;
}
}

// ---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -214,8 +218,7 @@ public AliasesRequest build() {

// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
params.put("format", "json");
Map<String, String> params = new HashMap<>(request.queryParameters());
if (ApiTypeHelper.isDefined(request.expandWildcards)) {
params.put("expand_wildcards",
request.expandWildcards.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@
import org.opensearch.client.transport.endpoints.SimpleEndpoint;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

// typedef: cat.allocation.Request

Expand All @@ -68,7 +67,7 @@ public class AllocationRequest extends CatRequestBase {
// ---------------------------------------------------------------------------------------------

private AllocationRequest(Builder builder) {

super(builder);
this.bytes = builder.bytes;
this.nodeId = ApiTypeHelper.unmodifiable(builder.nodeId);

Expand Down Expand Up @@ -103,7 +102,7 @@ public final List<String> nodeId() {
* Builder for {@link AllocationRequest}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<AllocationRequest> {
public static class Builder extends CatRequestBaseBuilder<AllocationRequest.Builder> {
@Nullable
private Bytes bytes;

Expand Down Expand Up @@ -155,6 +154,11 @@ public AllocationRequest build() {

return new AllocationRequest(this);
}

@Override
protected Builder self() {
return this;
}
}

// ---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -200,8 +204,7 @@ public AllocationRequest build() {

// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
params.put("format", "json");
Map<String, String> params = new HashMap<>(request.queryParameters());
if (request.bytes != null) {
params.put("bytes", request.bytes.jsonValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,99 @@
package org.opensearch.client.opensearch.cat;

import org.opensearch.client.opensearch._types.RequestBase;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;

// typedef: cat._types.CatRequestBase
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;

// typedef: cat._types.CatRequestBase


public abstract class CatRequestBase extends RequestBase {
public CatRequestBase() {
}

protected abstract static class AbstractBuilder<BuilderT extends AbstractBuilder<BuilderT>>
extends
ObjectBuilderBase {
protected abstract BuilderT self();
@Nullable
private final String headers;

@Nullable
private final String sort;

public CatRequestBase() {
this.headers = null;
this.sort = null;
}

public CatRequestBase(CatRequestBaseBuilder<?> builder) {
this.headers = builder.headers;
this.sort = builder.sort;
}

protected final Map<String, String> queryParameters() {
Map<String, String> params = new HashMap<>();
if (headers != null && !headers.isBlank()) {
params.put("h", headers);
}
if(sort != null && !sort.isBlank()) {
params.put("s", sort);
}
params.put("format", "json");
return params;
}


/**
* A comma-separated list of headers to limit the returned information
* <p>
* API name: {@code h}
*/
public final String headers() {
return this.headers;
}

/**
* A comma-separated list of headers to sort the returned information
* <p>
* API name: {@code s}
* <p>
*/
public final String sort() {
return this.sort;
}


protected abstract static class CatRequestBaseBuilder<BuilderT extends CatRequestBaseBuilder> extends ObjectBuilderBase implements ObjectBuilder {

@Nullable
protected String headers;

@Nullable
protected String sort;

protected abstract BuilderT self();

/**
* A comma-separated list of specific headers to limits the output
* <p>
* API name: {@code h}
* <p>
*/
public final BuilderT headers(@Nullable String headers) {
this.headers = headers;
return self();
}

/**
* A comma-separated list of headers to sort the returned information
* <p>
* API name: {@code s}
* <p>
*/
public final BuilderT sort(@Nullable String sort) {
this.sort = sort;
return self();
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.opensearch.client.transport.endpoints.SimpleEndpoint;

import java.util.HashMap;
import java.util.Map;

// typedef: cat.cluster_manager.Request

Expand Down Expand Up @@ -79,12 +78,7 @@ public ClusterManagerRequest() {
},

// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
params.put("format", "json");
return params;

}, SimpleEndpoint.emptyMap(), false, ClusterManagerResponse._DESERIALIZER);
request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, ClusterManagerResponse._DESERIALIZER);

/**
* Endpoint "{@code cat.cluster_manager}".
Expand All @@ -104,10 +98,5 @@ public ClusterManagerRequest() {
},

// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
params.put("format", "json");
return params;

}, SimpleEndpoint.emptyMap(), false, ClusterManagerResponse._DESERIALIZER);
request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, ClusterManagerResponse._DESERIALIZER);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@
import org.opensearch.client.transport.endpoints.SimpleEndpoint;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

// typedef: cat.count.Request

Expand All @@ -64,7 +62,7 @@ public class CountRequest extends CatRequestBase {
// ---------------------------------------------------------------------------------------------

private CountRequest(Builder builder) {

super(builder);
this.index = ApiTypeHelper.unmodifiable(builder.index);

}
Expand All @@ -88,7 +86,7 @@ public final List<String> index() {
* Builder for {@link CountRequest}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<CountRequest> {
public static class Builder extends CatRequestBaseBuilder<CountRequest.Builder> {
@Nullable
private List<String> index;

Expand Down Expand Up @@ -127,6 +125,11 @@ public CountRequest build() {

return new CountRequest(this);
}

@Override
protected Builder self() {
return this;
}
}

// ---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -170,10 +173,5 @@ public CountRequest build() {
},

// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
params.put("format", "json");
return params;

}, SimpleEndpoint.emptyMap(), false, CountResponse._DESERIALIZER);
request -> new HashMap<>(request.queryParameters()), SimpleEndpoint.emptyMap(), false, CountResponse._DESERIALIZER);
}
Loading

0 comments on commit 938170a

Please sign in to comment.