Skip to content

Commit

Permalink
Merge branch 'main' into Fix-283
Browse files Browse the repository at this point in the history
Signed-off-by: Uriel Dan Nudelman <urinud@gmail.com>
  • Loading branch information
urinud committed Jun 28, 2023
2 parents ecffe3a + 1323796 commit da1b49e
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 242 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Migrate client transports to Apache HttpClient / Core 5.x ([#246](https://github.com/opensearch-project/opensearch-java/pull/246))

### Deprecated
- Deprecate RestClientTransport ((#536)[https://github.com/opensearch-project/opensearch-java/pull/536])

### Removed

Expand All @@ -28,13 +29,16 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Added
- Add support for knn_vector field type ([#529](https://github.com/opensearch-project/opensearch-java/pull/524))
- Add translog option object and missing translog sync interval option in index settings ([#518](https://github.com/opensearch-project/opensearch-java/pull/518))
- Adds the option to set slices=auto for UpdateByQueryRequest, DeleteByQueryRequest and ReindexRequest ([#538](https://github.com/opensearch-project/opensearch-java/pull/538))

### Dependencies
- Bumps `jackson` from 2.14.2 to 2.15.2 ((#537)[https://github.com/opensearch-project/opensearch-java/pull/537])

### Changed

### Deprecated
- Deprecate translogDurability and translogFlushThresholdSize in IndexSettings in favor of a separate translog object ([#518](https://github.com/opensearch-project/opensearch-java/pull/518))

### Removed

Expand Down
58 changes: 29 additions & 29 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,7 @@ static class IndexData {

## Create a client

There are multiple low level transports which `OpenSearchClient` could be configured with.

### Create a client using `RestClientTransport`

```java
import org.apache.hc.core5.http.HttpHost;

final HttpHost[] hosts = new HttpHost[] {
new HttpHost("http", "localhost", 9200)
};

// Initialize the client with SSL and TLS enabled
final RestClient restClient = RestClient
.builder(hosts)
.build();

OpenSearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
OpenSearchClient client = new OpenSearchClient(transport);
```

The `JacksonJsonpMapper` class (2.x versions) only supports Java 7 objects by default. [Java 8 modules](https://github.com/FasterXML/jackson-modules-java8) to support JDK8 classes such as the Date and Time API (JSR-310), `Optional`, and more can be used by including [the additional datatype dependency](https://github.com/FasterXML/jackson-modules-java8#usage) and adding the module. For example, to include JSR-310 classes:

```java
OpenSearchTransport transport = new RestClientTransport(restClient,
new JacksonJsonpMapper(new ObjectMapper().registerModule(new JavaTimeModule())));
OpenSearchClient client = new OpenSearchClient(transport);
```

Upcoming OpenSearch `3.0.0` release brings HTTP/2 support and as such, the `RestClientTransport` would switch to HTTP/2 if available (for both HTTPS and/or HTTP protocols). The desired protocol could be forced using `RestClientBuilder.HttpClientConfigCallback`.
There are multiple low level transports which `OpenSearchClient` could be configured with, the `ApacheHttpClient5Transport` being the default one.

### Create a client using `ApacheHttpClient5Transport`

Expand Down Expand Up @@ -143,6 +115,34 @@ final OpenSearchTransport transport = ApacheHttpClient5TransportBuilder
OpenSearchClient client = new OpenSearchClient(transport);
```

### Create a client using `RestClientTransport` (deprecated)

```java
import org.apache.hc.core5.http.HttpHost;

final HttpHost[] hosts = new HttpHost[] {
new HttpHost("http", "localhost", 9200)
};

// Initialize the client with SSL and TLS enabled
final RestClient restClient = RestClient
.builder(hosts)
.build();

OpenSearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
OpenSearchClient client = new OpenSearchClient(transport);
```

The `JacksonJsonpMapper` class (2.x versions) only supports Java 7 objects by default. [Java 8 modules](https://github.com/FasterXML/jackson-modules-java8) to support JDK8 classes such as the Date and Time API (JSR-310), `Optional`, and more can be used by including [the additional datatype dependency](https://github.com/FasterXML/jackson-modules-java8#usage) and adding the module. For example, to include JSR-310 classes:

```java
OpenSearchTransport transport = new RestClientTransport(restClient,
new JacksonJsonpMapper(new ObjectMapper().registerModule(new JavaTimeModule())));
OpenSearchClient client = new OpenSearchClient(transport);
```

Upcoming OpenSearch `3.0.0` release brings HTTP/2 support and as such, the `RestClientTransport` would switch to HTTP/2 if available (for both HTTPS and/or HTTP protocols). The desired protocol could be forced using `RestClientBuilder.HttpClientConfigCallback`.

## Create an index

### Create an index with default settings
Expand Down
10 changes: 7 additions & 3 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,17 @@ val integrationTest = task<Test>("integrationTest") {
dependencies {

val opensearchVersion = "3.0.0-SNAPSHOT"
val jacksonVersion = "2.14.2"
val jacksonDatabindVersion = "2.14.2"
val jacksonVersion = "2.15.2"
val jacksonDatabindVersion = "2.15.2"

// Apache 2.0
implementation("org.opensearch.client", "opensearch-rest-client", opensearchVersion)
compileOnly("org.opensearch.client", "opensearch-rest-client", opensearchVersion)
testImplementation("org.opensearch.test", "framework", opensearchVersion)

api("org.apache.httpcomponents.client5:httpclient5:5.1.4")
api("org.apache.httpcomponents.core5:httpcore5:5.1.5")
api("org.apache.httpcomponents.core5:httpcore5-h2:5.1.5")

// Apache 2.0
// https://search.maven.org/artifact/com.google.code.findbugs/jsr305
api("com.google.code.findbugs:jsr305:3.0.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@

package org.opensearch.client.opensearch.indices;

import org.opensearch.client.opensearch._types.Time;
import jakarta.json.stream.JsonGenerator;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.opensearch._types.Time;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;

import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Function;
import javax.annotation.Nullable;

// typedef: indices._types.IndexSettings

Expand Down Expand Up @@ -199,10 +200,7 @@ public class IndexSettings implements JsonpSerializable {
private final Integer maxSlicesPerScroll;

@Nullable
private final String translogDurability;

@Nullable
private final String translogFlushThresholdSize;
private final Translog translog;

@Nullable
private final Boolean queryStringLenient;
Expand Down Expand Up @@ -280,8 +278,7 @@ private IndexSettings(Builder builder) {
this.verifiedBeforeClose = builder.verifiedBeforeClose;
this.format = builder.format;
this.maxSlicesPerScroll = builder.maxSlicesPerScroll;
this.translogDurability = builder.translogDurability;
this.translogFlushThresholdSize = builder.translogFlushThresholdSize;
this.translog = builder.translog;
this.queryStringLenient = builder.queryStringLenient;
this.priority = builder.priority;
this.topMetricsMaxSize = builder.topMetricsMaxSize;
Expand Down Expand Up @@ -680,20 +677,32 @@ public final Integer maxSlicesPerScroll() {
return this.maxSlicesPerScroll;
}

/**
* API name: {@code translog}
*/
@Nullable
public final Translog translog() {
return this.translog;
}

/**
* API name: {@code translog.durability}
* @deprecated use {@link #translog()} instead
*/
@Deprecated
@Nullable
public final String translogDurability() {
return this.translogDurability;
return this.translog != null ? this.translog.durability() : null;
}

/**
* API name: {@code translog.flush_threshold_size}
* @deprecated use {@link #translog()} instead
*/
@Deprecated
@Nullable
public final String translogFlushThresholdSize() {
return this.translogFlushThresholdSize;
return this.translog != null ? this.translog.flushThresholdSize() : null;
}

/**
Expand Down Expand Up @@ -1016,14 +1025,9 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.write(this.maxSlicesPerScroll);

}
if (this.translogDurability != null) {
generator.writeKey("translog.durability");
generator.write(this.translogDurability);

}
if (this.translogFlushThresholdSize != null) {
generator.writeKey("translog.flush_threshold_size");
generator.write(this.translogFlushThresholdSize);
if (this.translog != null) {
generator.writeKey("translog");
this.translog.serialize(generator, mapper);

}
if (this.queryStringLenient != null) {
Expand Down Expand Up @@ -1221,10 +1225,7 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<I
private Integer maxSlicesPerScroll;

@Nullable
private String translogDurability;

@Nullable
private String translogFlushThresholdSize;
private Translog translog;

@Nullable
private Boolean queryStringLenient;
Expand Down Expand Up @@ -1716,19 +1717,43 @@ public final Builder maxSlicesPerScroll(@Nullable Integer value) {
return this;
}

/**
* API name: {@code translog}
*/
public final Builder translog(@Nullable Translog value) {
this.translog = value;
return this;
}

/**
* API name: {@code translog.durability}
* @deprecated use {@link #translog()} instead
*/
@Deprecated
public final Builder translogDurability(@Nullable String value) {
this.translogDurability = value;
if (translog == null) {
translog = Translog.of(b -> b.durability(value));
} else {
translog = Translog.of(b -> b.durability(value)
.flushThresholdSize(translog.flushThresholdSize())
.syncInterval(translog.syncInterval()));
}
return this;
}

/**
* API name: {@code translog.flush_threshold_size}
* @deprecated use {@link #translog()} instead
*/
@Deprecated
public final Builder translogFlushThresholdSize(@Nullable String value) {
this.translogFlushThresholdSize = value;
if (translog == null) {
translog = Translog.of(b -> b.flushThresholdSize(value));
} else {
translog = Translog.of(b -> b.flushThresholdSize(value)
.durability(translog.durability())
.syncInterval(translog.syncInterval()));
}
return this;
}

Expand Down Expand Up @@ -1920,6 +1945,7 @@ protected static void setupIndexSettingsDeserializer(ObjectDeserializer<IndexSet
op.add(Builder::format, JsonpDeserializer.stringDeserializer(), "format", "index.format");
op.add(Builder::maxSlicesPerScroll, JsonpDeserializer.integerDeserializer(), "max_slices_per_scroll",
"index.max_slices_per_scroll");
op.add(Builder::translog, Translog._DESERIALIZER, "translog", "index.translog");
op.add(Builder::translogDurability, JsonpDeserializer.stringDeserializer(), "translog.durability",
"index.translog.durability");
op.add(Builder::translogFlushThresholdSize, JsonpDeserializer.stringDeserializer(),
Expand Down
Loading

0 comments on commit da1b49e

Please sign in to comment.