Skip to content

Commit

Permalink
spotlessApply
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <vachshah@amazon.com>
  • Loading branch information
VachaShah committed Oct 31, 2023
1 parent 6674dee commit 7b945c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
if (this.id != null) {
generator.writeKey("_id");
generator.write(this.id);
}
}

if (this.score != null) {
generator.writeKey("_score");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;

import org.junit.Test;
import org.opensearch.client.opensearch._types.FieldValue;
import org.opensearch.client.opensearch._types.SortOrder;
Expand All @@ -27,7 +26,8 @@ public abstract class AbstractSearchRequestIT extends OpenSearchJavaClientTestCa
@Test
public void shouldReturnSearchResults() throws Exception {
final String index = "search_request";
assertTrue(javaClient().indices()
assertTrue(
javaClient().indices()
.create(
b -> b.index(index)
.mappings(
Expand All @@ -36,7 +36,8 @@ public void shouldReturnSearchResults() throws Exception {
)
.settings(settings -> settings.sort(s -> s.field("name").order(SegmentSortOrder.Asc)))
)
.acknowledged());
.acknowledged()
);

createTestDocuments(index);
javaClient().indices().refresh();
Expand All @@ -58,14 +59,23 @@ public void shouldReturnSearchResults() throws Exception {
final SearchResponse<ShopItem> response = javaClient().search(request, ShopItem.class);
assertEquals(response.hits().hits().size(), 2);

assertTrue(Arrays.stream(response.hits().hits().get(0).fields().get("name").to(String[].class)).collect(Collectors.toList()).contains("hummer"));
assertTrue(Arrays.stream(response.hits().hits().get(1).fields().get("name").to(String[].class)).collect(Collectors.toList()).contains("jammer"));
assertTrue(
Arrays.stream(response.hits().hits().get(0).fields().get("name").to(String[].class))
.collect(Collectors.toList())
.contains("hummer")
);
assertTrue(
Arrays.stream(response.hits().hits().get(1).fields().get("name").to(String[].class))
.collect(Collectors.toList())
.contains("jammer")
);
}

@Test
public void shouldReturnSearchResultsWithoutStoredFields() throws Exception {
final String index = "search_request";
assertTrue(javaClient().indices()
assertTrue(
javaClient().indices()
.create(
b -> b.index(index)
.mappings(
Expand All @@ -74,7 +84,8 @@ public void shouldReturnSearchResultsWithoutStoredFields() throws Exception {
)
.settings(settings -> settings.sort(s -> s.field("name").order(SegmentSortOrder.Asc)))
)
.acknowledged());
.acknowledged()
);

createTestDocuments(index);
javaClient().indices().refresh();
Expand All @@ -86,10 +97,7 @@ public void shouldReturnSearchResultsWithoutStoredFields() throws Exception {
);

final SearchRequest request = SearchRequest.of(
r -> r.index(index)
.sort(s -> s.field(f -> f.field("name").order(SortOrder.Asc)))
.query(query)
.storedFields("_none_")
r -> r.index(index).sort(s -> s.field(f -> f.field("name").order(SortOrder.Asc))).query(query).storedFields("_none_")
);

final SearchResponse<ShopItem> response = javaClient().search(request, ShopItem.class);
Expand Down

0 comments on commit 7b945c5

Please sign in to comment.