diff --git a/samples/src/main/java/org/opensearch/client/samples/Bulk.java b/samples/src/main/java/org/opensearch/client/samples/Bulk.java
index 4467c07c92..ee5e2bb5fa 100644
--- a/samples/src/main/java/org/opensearch/client/samples/Bulk.java
+++ b/samples/src/main/java/org/opensearch/client/samples/Bulk.java
@@ -8,8 +8,9 @@
package org.opensearch.client.samples;
-import java.util.ArrayList;
+import static org.opensearch.client.samples.util.CommonUtil.search;
+import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.client.opensearch.OpenSearchClient;
@@ -23,8 +24,6 @@
import org.opensearch.client.samples.util.CommonUtil;
import org.opensearch.client.samples.util.IndexData;
-import static org.opensearch.client.samples.util.CommonUtil.search;
-
/**
* Run with: ./gradlew :samples:run -Dsamples.mainClass=Bulk
*/
@@ -32,6 +31,7 @@ public class Bulk {
private static final Logger LOGGER = LogManager.getLogger(Bulk.class);
private static OpenSearchClient client;
private static final String indexName = "my-index";
+
public static void main(String[] args) {
try {
client = SampleClient.create();
@@ -65,8 +65,9 @@ public static void main(String[] args) {
LOGGER.info("Found {} with score {} and id {}", hit.source(), hit.score(), hit.id());
IndexData finalSearchedData = hit.source();
finalSearchedData.setText("Updated document");
- BulkRequest request = new BulkRequest.Builder().operations(o -> o.update(u -> u.index(indexName)
- .id(hit.id()).document(finalSearchedData))).build();
+ BulkRequest request = new BulkRequest.Builder().operations(
+ o -> o.update(u -> u.index(indexName).id(hit.id()).document(finalSearchedData))
+ ).build();
bulkResponse = client.bulk(request);
LOGGER.info("Bulk update response items: {}", bulkResponse.items().size());
}
diff --git a/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java b/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java
index 2b63643ff2..aa5b28c624 100644
--- a/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java
+++ b/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java
@@ -14,18 +14,13 @@
import org.opensearch.client.json.JsonData;
import org.opensearch.client.opensearch._types.mapping.DynamicMapping;
import org.opensearch.client.opensearch._types.mapping.FieldNamesField;
-import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty;
-import org.opensearch.client.opensearch._types.mapping.Property;
import org.opensearch.client.opensearch._types.mapping.RoutingField;
import org.opensearch.client.opensearch._types.mapping.SourceField;
-import org.opensearch.client.opensearch._types.mapping.TypeMapping;
import org.opensearch.client.opensearch.core.IndexRequest;
import org.opensearch.client.opensearch.core.SearchResponse;
-import org.opensearch.client.opensearch.indices.CreateIndexRequest;
import org.opensearch.client.opensearch.indices.DeleteIndexRequest;
import org.opensearch.client.opensearch.indices.GetMappingRequest;
import org.opensearch.client.opensearch.indices.GetMappingResponse;
-import org.opensearch.client.opensearch.indices.IndexSettings;
import org.opensearch.client.opensearch.indices.PutMappingRequest;
import org.opensearch.client.samples.util.CommonUtil;
import org.opensearch.client.samples.util.IndexData;
diff --git a/samples/src/main/java/org/opensearch/client/samples/PointInTime.java b/samples/src/main/java/org/opensearch/client/samples/PointInTime.java
index bdbd54abcf..1e8773aba2 100644
--- a/samples/src/main/java/org/opensearch/client/samples/PointInTime.java
+++ b/samples/src/main/java/org/opensearch/client/samples/PointInTime.java
@@ -12,17 +12,12 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.client.opensearch._types.Time;
-import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty;
-import org.opensearch.client.opensearch._types.mapping.Property;
-import org.opensearch.client.opensearch._types.mapping.TypeMapping;
import org.opensearch.client.opensearch.core.pit.CreatePitRequest;
import org.opensearch.client.opensearch.core.pit.CreatePitResponse;
import org.opensearch.client.opensearch.core.pit.DeletePitRequest;
import org.opensearch.client.opensearch.core.pit.DeletePitResponse;
import org.opensearch.client.opensearch.core.pit.ListAllPitResponse;
-import org.opensearch.client.opensearch.indices.CreateIndexRequest;
import org.opensearch.client.opensearch.indices.DeleteIndexRequest;
-import org.opensearch.client.opensearch.indices.IndexSettings;
import org.opensearch.client.samples.util.CommonUtil;
/**
diff --git a/samples/src/main/java/org/opensearch/client/samples/Search.java b/samples/src/main/java/org/opensearch/client/samples/Search.java
index a2bbf9bbd3..31927b883a 100644
--- a/samples/src/main/java/org/opensearch/client/samples/Search.java
+++ b/samples/src/main/java/org/opensearch/client/samples/Search.java
@@ -35,7 +35,6 @@
import org.opensearch.client.opensearch.core.search.PhraseSuggester;
import org.opensearch.client.opensearch.core.search.Suggester;
import org.opensearch.client.opensearch.core.search.TermSuggester;
-import org.opensearch.client.opensearch.indices.CreateIndexRequest;
import org.opensearch.client.opensearch.indices.DeleteIndexRequest;
import org.opensearch.client.opensearch.indices.IndexSettings;
import org.opensearch.client.opensearch.indices.IndexSettingsAnalysis;
diff --git a/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java b/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java
index 70551ecad5..1914bbd2d1 100644
--- a/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java
+++ b/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java
@@ -1,5 +1,7 @@
package org.opensearch.client.samples.util;
+import java.io.IOException;
+import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.client.opensearch.OpenSearchClient;
@@ -12,34 +14,33 @@
import org.opensearch.client.opensearch.indices.CreateIndexRequest;
import org.opensearch.client.opensearch.indices.IndexSettings;
-import java.io.IOException;
-import java.util.List;
-
-
public class CommonUtil {
private static final Logger LOGGER = LogManager.getLogger(CommonUtil.class);
+
public static void createIndex(OpenSearchClient client, String indexName) throws IOException {
if (!client.indices().exists(r -> r.index(indexName)).value()) {
LOGGER.info("Creating index {}", indexName);
IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build();
TypeMapping mapping = new TypeMapping.Builder().properties(
- "age",
- new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build()
+ "age",
+ new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build()
).build();
CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName)
- .settings(settings)
- .mappings(mapping)
- .build();
+ .settings(settings)
+ .mappings(mapping)
+ .build();
client.indices().create(createIndexRequest);
}
}
- public static SearchResponse search(OpenSearchClient client, String indexName, String field, String value) throws IOException {
+
+ public static SearchResponse search(OpenSearchClient client, String indexName, String field, String value)
+ throws IOException {
Query query = Query.of(qb -> qb.match(mb -> mb.field(field).query(fv -> fv.stringValue(value))));
final SearchRequest.Builder searchReq = new SearchRequest.Builder().allowPartialSearchResults(false)
- .index(List.of(indexName))
- .size(10)
- .ignoreThrottled(false)
- .query(query);
+ .index(List.of(indexName))
+ .size(10)
+ .ignoreThrottled(false)
+ .query(query);
return client.search(searchReq.build(), IndexData.class);
}
}