Skip to content

Commit

Permalink
Merge branch 'main' into issue-379
Browse files Browse the repository at this point in the history
  • Loading branch information
L00kian authored Mar 7, 2023
2 parents a49f1e7 + 9b9ec00 commit e87ab08
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 15 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- id: get_data
run: |
echo "approvers=$(cat .github/CODEOWNERS | grep @ | tr -d '* ' | sed 's/@/,/g' | sed 's/,//1')" >> $GITHUB_OUTPUT
echo "version=$(cat gradle.properties | grep "systemProp.version" | cut -d'=' -f2)" >> $GITHUB_OUTPUT
- uses: trstringer/manual-approval@v1
with:
secret: ${{ github.TOKEN }}
approvers: ${{ steps.get_data.outputs.approvers }}
minimum-approvals: 2
issue-title: 'Release opensearch-java : ${{ steps.get_data.outputs.version }}'
issue-body: "Please approve or deny the release of opensearch-java. **VERSION**: ${{ steps.get_data.outputs.version }} **TAG**: ${{ github.ref_name }} **COMMIT**: ${{ github.sha }}"
exclude-workflow-initiator-as-approver: true
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]
### Dependencies
- Bumps `io.github.classgraph:classgraph` from 4.8.154 to 4.8.156

### Added
- Add GitHub workflow for changelog verification ([#239](https://github.com/opensearch-project/opensearch-java/pull/239))
Expand All @@ -12,6 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Add new `OpenSearchTransport` based on Apache HttpClient 5 ([#281](https://github.com/opensearch-project/opensearch-java/pull/281))
- Add workflow to publish snapshots via GHA ([#325](https://github.com/opensearch-project/opensearch-java/pull/325))
- Document HTTP/2 support ([#330](https://github.com/opensearch-project/opensearch-java/pull/330))
- 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))

### Dependencies
Expand All @@ -35,8 +38,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Update Gradle to 7.6 ([#309](https://github.com/opensearch-project/opensearch-java/pull/309))
- Prevent SPI calls at runtime ([#293](https://github.com/opensearch-project/opensearch-java/pull/293))
- Add support for OpenSearch Serverless ([#339](https://github.com/opensearch-project/opensearch-java/pull/339))
- Fix issue where completion suggestions were failing, due to being parsed as term suggestions ([#107](https://github.com/opensearch-project/opensearch-java/issues/107))
- Fix integration tests ([#375](https://github.com/opensearch-project/opensearch-java/pull/375))
- Fix completion suggestions failure with missing required property TermSuggestOption.score ([#347](https://github.com/opensearch-project/opensearch-java/pull/347))
- Fix search failure with missing required property HitsMetadata.total when trackTotalHits is disabled ([#372](https://github.com/opensearch-project/opensearch-java/pull/372))

### Deprecated

Expand Down
6 changes: 4 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ Repositories create consistent release labels, such as `v1.0.0`, `v1.1.0` and `v
The release process is standard across repositories in this org and is run by a release manager volunteering from amongst [MAINTAINERS](MAINTAINERS.md).

1. Create a tag, e.g. `v2.1.0`, and push it to the GitHub repo.
2. This creates a draft release which triggers the [opensearch-java-maven-sign-and-release/](https://build.ci.opensearch.org/job/opensearch-java-maven-sign-and-release/) jenkins workflow. The artifacts will be automcatically signed and published to maven.
3. Increment `systemProp.version` in [gradle.properties](gradle.properties) to the next patch release, e.g. `v2.1.1`, commit and push.
1. The [release-drafter.yml](.github/workflows/release-drafter.yml) will be automatically kicked off and is responsible for drafting a new release on GitHub containing release artifacts.
1. Before creating a draft release, this workflow creates a GitHub issue asking for approval from the [maintainers](MAINTAINERS.md). See sample [issue](https://github.com/gaiksaya/opensearch-java/issues/1). The maintainers need to approve in order to continue the workflow run.
1. Once a release is drafted [opensearch-java-maven-sign-and-release/](https://build.ci.opensearch.org/job/opensearch-java-maven-sign-and-release/) jenkins workflow is triggered. The artifacts will be automcatically signed and published to maven.
1. Increment `systemProp.version` in [gradle.properties](gradle.properties) to the next patch release, e.g. `v2.1.1`, commit and push.
12 changes: 12 additions & 0 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [Create an index](#create-an-index)
- [Index data](#index-data)
- [Search for the documents](#search-for-the-documents)
- [Get raw JSON results](#get-raw-json-results)
- [Search documents using a match query](#search-documents-using-a-match-query)
- [Bulk requests](#bulk-requests)
- [Aggregations](#aggregations)
Expand Down Expand Up @@ -130,6 +131,17 @@ for (int i = 0; i < searchResponse.hits().hits().size(); i++) {
}
```

### Get raw JSON results

When the target class is not defined or if the response result is a semi-structured data not tied to an object definition, use a raw JSON data representation as the target class. For example, the below snippet uses `ObjectNode` from jackson.

```java
SearchResponse<ObjectNode> searchResponse = client.search(b -> b.index(index), ObjectNode.class);
for (int i = 0; i < searchResponse.hits().hits().size(); i++) {
System.out.println(searchResponse.hits().hits().get(i).source());
}
```

## Search documents using a match query

```java
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=7ba68c54029790ab444b39d7e293d3236b2632631fb5f2e012bb28b4ff669e4b
distributionSha256Sum=ff7bf6a86f09b9b2c40bb8f48b25fc19cf2b2664fd1d220cd7ab833ec758d0d7
4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down
2 changes: 1 addition & 1 deletion java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ dependencies {
implementation("org.eclipse", "yasson", "2.0.2")

// https://github.com/classgraph/classgraph
testImplementation("io.github.classgraph:classgraph:4.8.154")
testImplementation("io.github.classgraph:classgraph:4.8.156")

// Eclipse 1.0
testImplementation("junit", "junit" , "4.13.2") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@


public class HitsMetadata<T> implements JsonpSerializable {
@Nullable
private final TotalHits total;

private final List<Hit<T>> hits;
Expand All @@ -70,7 +71,7 @@ public class HitsMetadata<T> implements JsonpSerializable {

private HitsMetadata(Builder<T> builder) {

this.total = ApiTypeHelper.requireNonNull(builder.total, this, "total");
this.total = builder.total;
this.hits = ApiTypeHelper.unmodifiableRequired(builder.hits, this, "hits");
this.maxScore = builder.maxScore;
this.tSerializer = builder.tSerializer;
Expand All @@ -82,7 +83,7 @@ public static <T> HitsMetadata<T> of(Function<Builder<T>, ObjectBuilder<HitsMeta
}

/**
* Required - API name: {@code total}
* API name: {@code total}
*/
public final TotalHits total() {
return this.total;
Expand Down Expand Up @@ -114,8 +115,10 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) {

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

generator.writeKey("total");
this.total.serialize(generator, mapper);
if (this.total != null) {
generator.writeKey("total");
this.total.serialize(generator, mapper);
}

if (ApiTypeHelper.isDefined(this.hits)) {
generator.writeKey("hits");
Expand All @@ -142,6 +145,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
*/

public static class Builder<T> extends ObjectBuilderBase implements ObjectBuilder<HitsMetadata<T>> {
@Nullable
private TotalHits total;

private List<Hit<T>> hits;
Expand All @@ -153,15 +157,15 @@ public static class Builder<T> extends ObjectBuilderBase implements ObjectBuilde
private JsonpSerializer<T> tSerializer;

/**
* Required - API name: {@code total}
* API name: {@code total}
*/
public final Builder<T> total(TotalHits value) {
this.total = value;
return this;
}

/**
* Required - API name: {@code total}
* API name: {@code total}
*/
public final Builder<T> total(Function<TotalHits.Builder, ObjectBuilder<TotalHits>> fn) {
return this.total(fn.apply(new TotalHits.Builder()).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.opensearch.client.opensearch.core.search.CompletionSuggester;
import org.opensearch.client.opensearch.core.search.FieldSuggester;
import org.opensearch.client.opensearch.core.search.FieldSuggesterBuilders;
import org.opensearch.client.opensearch.core.search.Hit;
import org.opensearch.client.opensearch.core.search.Suggester;
import org.opensearch.client.opensearch.indices.CreateIndexResponse;
import org.opensearch.client.opensearch.indices.GetIndexResponse;
Expand Down Expand Up @@ -314,6 +315,37 @@ public void testBulkRequest() throws IOException {
assertEquals(42, javaClient().get(b -> b.index("foo").id("abc"), AppData.class).source().getIntValue());
}

@Test
public void testTrackTotalHitsFalse() throws Exception {
// https://github.com/opensearch-project/opensearch-java/issues/354
String index = "ingest-test";

javaClient().indices().create(b -> b.index(index));

AppData appData = new AppData();
appData.setIntValue(1337);
appData.setMsg("foo");

javaClient().index(b -> b
.index(index)
.id("myId")
.document(appData)
.refresh(Refresh.True) // Make it visible for search
).id();

// Search
SearchResponse<AppData> search = javaClient().search(b -> b
.index(index)
.trackTotalHits(t -> t.enabled(false))
, AppData.class
);

List<Hit<AppData>> hits = search.hits().hits();
AppData appDataResult = search.hits().hits().get(0).source();
assertEquals(1337, appDataResult.getIntValue());
assertEquals("foo", appDataResult.getMsg());
}

@Test
public void testRefresh() throws IOException {
AppData appData = new AppData();
Expand Down

0 comments on commit e87ab08

Please sign in to comment.