Skip to content

Commit

Permalink
Merge branch 'main' into radial-search
Browse files Browse the repository at this point in the history
Signed-off-by: alex-keeler <[email protected]>
  • Loading branch information
alex-keeler authored Sep 12, 2024
2 parents a88ee27 + cb89246 commit c76761a
Show file tree
Hide file tree
Showing 179 changed files with 7,472 additions and 3,081 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased 3.0]
### Dependencies
- Bumps `org.junit:junit-bom` from 5.10.2 to 5.10.3
- Bumps `org.owasp.dependencycheck` from 10.0.2 to 10.0.3
- Bumps `org.owasp.dependencycheck` from 10.0.2 to 10.0.4
- Bumps `org.eclipse.parsson:parsson` from 1.1.6 to 1.1.7
- Bumps `org.hamcrest:hamcrest` from 2.2 to 3.0
- Bumps `com.github.jk1.dependency-license-report` from 2.8 to 2.9
Expand All @@ -21,6 +20,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
- Changed SearchAfter of SearchRequest type to FieldValue instead of String ([#769](https://github.com/opensearch-project/opensearch-java/pull/769))
- Changed type of `DanglingIndex`'s `creationDateMillis` field from `String` to `long` ([#1124](https://github.com/opensearch-project/opensearch-java/pull/1124))
- Changed type of `ShardStatistics`'s `total`, `successful`, `failed` & `skipped` fields from `Number` to `int/Integer` ([#1158](https://github.com/opensearch-project/opensearch-java/pull/1158))
- Unified `tasks.Info` and `tasks.State` classes into `tasks.TaskInfo` ([#1187](https://github.com/opensearch-project/opensearch-java/pull/1187))

### Deprecated
- Deprecate RestClientTransport ([#536](https://github.com/opensearch-project/opensearch-java/pull/536))
Expand All @@ -29,6 +29,7 @@ This section is for maintaining a changelog for all breaking changes for the cli

### Fixed
- Fix version and build ([#254](https://github.com/opensearch-project/opensearch-java/pull/254))
- Fixed deserializing `tasks.ListResponse` when using `GroupBy.None` ([#1187](https://github.com/opensearch-project/opensearch-java/pull/1187))

### Security

Expand All @@ -38,6 +39,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
- Added `minScore` and `maxDistance` to `KnnQuery` ([#1166](https://github.com/opensearch-project/opensearch-java/pull/1166))

### Dependencies
- Bumps `org.junit:junit-bom` from 5.10.3 to 5.11.0

### Changed

Expand All @@ -46,6 +48,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
### Removed

### Fixed
- Fix queries not preserving boost and name when converted to builders ([#1181](https://github.com/opensearch-project/opensearch-java/pull/1181))

### Security

Expand All @@ -54,6 +57,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
- Added `queryImage` (query_image) field to `NeuralQuery`, following definition in ([Neural Query](https://opensearch.org/docs/latest/query-dsl/specialized/neural/)) ([#1137](https://github.com/opensearch-project/opensearch-java/pull/1138))
- Added `cancelAfterTimeInterval` to `SearchRequest` and `MsearchRequest` ([#1147](https://github.com/opensearch-project/opensearch-java/pull/1147))
- Added the `ml` namespace operations ([#1158](https://github.com/opensearch-project/opensearch-java/pull/1158))
- Added `IndexTemplateMapping.Builder#withJson`, `SourceField.Builder#withJson` and `IndexSettings.Builder#withJson` for streamlining deserialization ([#1148](https://github.com/opensearch-project/opensearch-java/pull/1148))

### Dependencies
- Bumps `commons-logging:commons-logging` from 1.3.3 to 1.3.4
Expand Down Expand Up @@ -544,4 +548,4 @@ This section is for maintaining a changelog for all breaking changes for the cli
[2.5.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.4.0...v2.5.0
[2.4.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.3.0...v2.4.0
[2.3.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.2.0...v2.3.0
[2.2.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.1.0...v2.2.0
[2.2.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.1.0...v2.2.0
17 changes: 16 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@ After:

### ShardStatistics properties types
- The type of the `total`, `successful` and `failed` fields has been corrected from `Number` to `int`.
- The type of the `skipped` field has been corrected from `Number` to `Integer`.
- The type of the `skipped` field has been corrected from `Number` to `Integer`.

### Unified tasks.Info & tasks.State classes into tasks.TaskInfo
- The `tasks.Info` and `tasks.State` classes have been unified into `tasks.TaskInfo`, this affects:
- `TaskExecutingNode`'s `tasks` field.
- `GetTasksResponse`'s `task` field.
- `core.update_by_query_rethrottle.UpdateByQueryRethrottleNode`'s `tasks` field.
- The `headers` field is now a `Map<String, String>` instead of a `Map<String, List<String>>`.

### tasks.ListResponse properties lifted to tasks.TaskListResponseBase
- All fields previously defined on `tasks.ListResponse` have been lifted to `tasks.TaskListResponseBase`.
- `DeleteByQueryRethrottleResponse` now extends `tasks.TaskListResponseBase` instead of `tasks.ListResponse`.
- The `tasks` field is now a `TaskInfos` union type instead of a `Map<String, Info>` to correctly handle `groupBy` parents or none.

### GetTasksResponse response type
- The type of `GetTasksResponse`'s `response` field has been changed from `tasks.Status` to `tasks.TaskResponse`.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ allprojects {
mavenLocal()
maven(url = "https://aws.oss.sonatype.org/content/repositories/snapshots")
mavenCentral()
maven(url = "https://plugins.gradle.org/m2/")
gradlePluginPortal()
}
}

Expand Down
12 changes: 9 additions & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@
* GitHub history for details.
*/

dependencies {
implementation("org.ajoberstar.grgit:grgit-gradle:5.2.2")
plugins {
`kotlin-dsl`
}

repositories {
mavenLocal()
maven(url = "https://aws.oss.sonatype.org/content/repositories/snapshots")
mavenCentral()
maven(url = "https://plugins.gradle.org/m2/")
gradlePluginPortal()
}

dependencies {
implementation("org.ajoberstar.grgit:grgit-gradle:5.2.2")
implementation("com.diffplug.spotless", "spotless-plugin-gradle", "6.25.0")
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
plugins {
id("com.diffplug.spotless")
}

interface SpotlessConventionsPluginExtension {
val eclipseFormatterConfigFile: RegularFileProperty
}

val extension = project.extensions.create<SpotlessConventionsPluginExtension>("spotlessConventions")

extension.eclipseFormatterConfigFile.convention(rootProject.layout.projectDirectory.file("buildSrc/formatterConfig.xml"))

spotless {
java {
target("**/*.java")

licenseHeaderFile(rootProject.file("LICENSE_HEADER.txt"))
.named("PrimaryLicenseHeader")
.onlyIfContentMatches("^((?!Licensed to Elasticsearch)[\\s\\S])*$")
.delimiter("(package |//-----)")

licenseHeaderFile(rootProject.file("LICENSE_HEADER_FORKED.txt"))
.named("ForkedLicenseHeader")
.onlyIfContentMatches("Licensed to Elasticsearch")
.delimiter("(package |//-----)")

// Use the default importOrder configuration
importOrder()
removeUnusedImports()

eclipse().configFile(extension.eclipseFormatterConfigFile)

trimTrailingWhitespace()
endWithNewline()

// NOTE: Any time a custom step below is modified, bump this number.
// Allows up-to-date checks to work correctly with custom steps.
bumpThisNumberIfACustomStepChanges(1)

val wildcardImportRegex = Regex("""^import\s+(?:static\s+)?[^*\s]+\.\*;$""", RegexOption.MULTILINE)
custom("Refuse wildcard imports") { contents ->
// Wildcard imports can't be resolved by spotless itself.
// This will require the developer themselves to adhere to best practices.
val wildcardImports = wildcardImportRegex.findAll(contents)
if (wildcardImports.any()) {
var msg = """
Please replace the following wildcard imports with explicit imports ('spotlessApply' cannot resolve this issue):
""".trimIndent()
wildcardImports.forEach {
msg += "\n\t- ${it.value}"
}
msg += "\n"
throw AssertionError(msg)
}
contents
}
}
}
43 changes: 43 additions & 0 deletions guides/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
- [Serialization](#serialization)
- [Using toJsonString](#using-tojsonstring)
- [Manual Serialization](#manual-serialization)
- [Deserialization](#deserialization)
- [Using withJson](#using-withjson)
- [Using static _DESERIALIZER](#using-static-_deserializer)


# Working With JSON
Expand Down Expand Up @@ -50,4 +53,44 @@ private String toJson(JsonpSerializable object) {
throw new UncheckedIOException(ex);
}
}
```

## Deserialization

For demonstration let's consider an IndexTemplateMapping JSON String.

```java

String stringTemplate =
"{\"mappings\":{\"properties\":{\"age\":{\"type\":\"integer\"}}},\"settings\":{\"number_of_shards\":\"2\",\"number_of_replicas\":\"1\"}}";
```
### Using withJson
For classes, Builders of which implements `PlainDeserializable` interface, a default `withJson` method is provided.
The withJson method returns the Builder enabling you to chain Builder methods for additional configuration.
This implementation uses `jakarta.json.spi.JsonProvider` SPI to discover the available JSON provider instance
from the classpath and to create a new mapper. The `JsonpUtils` utility class streamlines this deserialization process.
The following code example demonstrates how to use the `withJson` method to deserialize objects:

```java
InputStream inputStream = new ByteArrayInputStream(stringTemplate.getBytes(StandardCharsets.UTF_8));
IndexTemplateMapping indexTemplateMapping = new IndexTemplateMapping.Builder().withJson(inputStream).build();
```


### Using static _DESERIALIZER
For classes annotated with `@JsonpDeserializable`, a static field _DESERIALIZER is provided,
which takes a mapper and a parser as arguments and returns the instance of the json value passed in the parser.
Notice that this way you cannot further customize the instance, the state of which will solely depend on the json value parsed.

The following sample code demonstrates how to serialize an instance of a Java class:

```java
private IndexTemplateMapping getInstance(String templateJsonString) {
InputStream inputStream = new ByteArrayInputStream(templateJsonString.getBytes(StandardCharsets.UTF_8));
JsonbJsonpMapper mapper = new JsonbJsonpMapper();
try (JsonParser parser = mapper.jsonProvider().createParser(inputStream)) {
IndexTemplateMapping indexTemplateMapping = new IndexTemplateMapping._DESERIALIZER.deserialize(parser, mapper);
return indexTemplateMapping;
}
}
```
32 changes: 4 additions & 28 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ buildscript {
mavenLocal()
maven(url = "https://aws.oss.sonatype.org/content/repositories/snapshots")
mavenCentral()
maven(url = "https://plugins.gradle.org/m2/")
gradlePluginPortal()
}
dependencies {
"classpath"(group = "org.opensearch.gradle", name = "build-tools", version = "3.0.0-SNAPSHOT")
Expand All @@ -52,8 +52,9 @@ plugins {
`java-library`
`maven-publish`
id("com.github.jk1.dependency-license-report") version "2.9"
id("org.owasp.dependencycheck") version "10.0.3"
id("com.diffplug.spotless") version "6.25.0"
id("org.owasp.dependencycheck") version "10.0.4"

id("opensearch-java.spotless-conventions")
}
apply(plugin = "opensearch.repositories")
apply(plugin = "org.owasp.dependencycheck")
Expand Down Expand Up @@ -299,31 +300,6 @@ tasks.withType<Jar> {
}
}

spotless {
java {
target("**/*.java")

licenseHeaderFile("../LICENSE_HEADER.txt")
.named("PrimaryLicenseHeader")
.onlyIfContentMatches("^((?!Licensed to Elasticsearch)[\\s\\S])*$")
.delimiter("(package |//-----)")

licenseHeaderFile("../LICENSE_HEADER_FORKED.txt")
.named("ForkedLicenseHeader")
.onlyIfContentMatches("Licensed to Elasticsearch")
.delimiter("(package |//-----)")

// Use the default importOrder configuration
importOrder()
removeUnusedImports()

eclipse().configFile("../buildSrc/formatterConfig.xml")

trimTrailingWhitespace()
endWithNewline()
}
}

publishing {
repositories{
if (version.toString().endsWith("SNAPSHOT")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,25 @@
import java.util.concurrent.CompletableFuture;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import org.opensearch.client.ApiClient;
import org.opensearch.client.opensearch._types.OpenSearchException;
import org.opensearch.client.opensearch.core.InfoRequest;
import org.opensearch.client.opensearch.core.InfoResponse;
import org.opensearch.client.opensearch.dangling_indices.OpenSearchDanglingIndicesAsyncClient;
import org.opensearch.client.opensearch.ml.OpenSearchMlAsyncClient;
import org.opensearch.client.opensearch.tasks.OpenSearchTasksAsyncClient;
import org.opensearch.client.transport.OpenSearchTransport;
import org.opensearch.client.transport.TransportOptions;

/**
* Client for the namespace.
*/
@Generated("org.opensearch.client.codegen.CodeGenerator")
public class OpenSearchAsyncClient extends OpenSearchAsyncClientBase<OpenSearchAsyncClient> {
public OpenSearchAsyncClient(OpenSearchTransport transport) {
super(transport, null);
}

public OpenSearchAsyncClient(OpenSearchTransport transport, @Nullable TransportOptions transportOptions) {
public abstract class OpenSearchAsyncClientBase<Self extends OpenSearchAsyncClientBase<Self>> extends ApiClient<OpenSearchTransport, Self> {
public OpenSearchAsyncClientBase(OpenSearchTransport transport, @Nullable TransportOptions transportOptions) {
super(transport, transportOptions);
}

@Override
public OpenSearchAsyncClient withTransportOptions(@Nullable TransportOptions transportOptions) {
return new OpenSearchAsyncClient(this.transport, transportOptions);
}

// ----- Child clients

public OpenSearchDanglingIndicesAsyncClient danglingIndices() {
Expand All @@ -76,6 +69,10 @@ public OpenSearchMlAsyncClient ml() {
return new OpenSearchMlAsyncClient(this.transport, this.transportOptions);
}

public OpenSearchTasksAsyncClient tasks() {
return new OpenSearchTasksAsyncClient(this.transport, this.transportOptions);
}

// ----- Endpoint: info

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,25 @@
import java.io.IOException;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import org.opensearch.client.ApiClient;
import org.opensearch.client.opensearch._types.OpenSearchException;
import org.opensearch.client.opensearch.core.InfoRequest;
import org.opensearch.client.opensearch.core.InfoResponse;
import org.opensearch.client.opensearch.dangling_indices.OpenSearchDanglingIndicesClient;
import org.opensearch.client.opensearch.ml.OpenSearchMlClient;
import org.opensearch.client.opensearch.tasks.OpenSearchTasksClient;
import org.opensearch.client.transport.OpenSearchTransport;
import org.opensearch.client.transport.TransportOptions;

/**
* Client for the namespace.
*/
@Generated("org.opensearch.client.codegen.CodeGenerator")
public class OpenSearchClient extends OpenSearchClientBase<OpenSearchClient> {
public OpenSearchClient(OpenSearchTransport transport) {
super(transport, null);
}

public OpenSearchClient(OpenSearchTransport transport, @Nullable TransportOptions transportOptions) {
public abstract class OpenSearchClientBase<Self extends OpenSearchClientBase<Self>> extends ApiClient<OpenSearchTransport, Self> {
public OpenSearchClientBase(OpenSearchTransport transport, @Nullable TransportOptions transportOptions) {
super(transport, transportOptions);
}

@Override
public OpenSearchClient withTransportOptions(@Nullable TransportOptions transportOptions) {
return new OpenSearchClient(this.transport, transportOptions);
}

// ----- Child clients

public OpenSearchDanglingIndicesClient danglingIndices() {
Expand All @@ -75,6 +68,10 @@ public OpenSearchMlClient ml() {
return new OpenSearchMlClient(this.transport, this.transportOptions);
}

public OpenSearchTasksClient tasks() {
return new OpenSearchTasksClient(this.transport, this.transportOptions);
}

// ----- Endpoint: info

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public final BuilderT acknowledged(boolean value) {

protected abstract BuilderT self();
}

// ---------------------------------------------------------------------------------------------

protected static <BuilderT extends AbstractBuilder<BuilderT>> void setupAcknowledgedResponseBaseDeserializer(
Expand Down
Loading

0 comments on commit c76761a

Please sign in to comment.