Skip to content

Commit

Permalink
changes made by spotlessApply
Browse files Browse the repository at this point in the history
Signed-off-by: Karthik Subramanian <[email protected]>
  • Loading branch information
karthiks3000 committed Oct 27, 2023
1 parent fb8aefa commit ea6ff7e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
11 changes: 6 additions & 5 deletions samples/src/main/java/org/opensearch/client/samples/Bulk.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,15 +24,14 @@
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: <c>./gradlew :samples:run -Dsamples.mainClass=Bulk</c>
*/
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();
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<IndexData> search(OpenSearchClient client, String indexName, String field, String value) throws IOException {

public static SearchResponse<IndexData> 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);
}
}

0 comments on commit ea6ff7e

Please sign in to comment.