Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing InnerHits storedFields ("stored_fields") generated Json name. #781

Merged
merged 4 commits into from
Dec 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
ran ./gradlew :java-client:spotlessApply
Signed-off-by: brentam <[email protected]>
  • Loading branch information
brentam committed Dec 23, 2023
commit 633741b926e590ab2ada272ba00b9bcfa8987497
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package org.opensearch.client.opensearch.core.search;

import jakarta.json.spi.JsonProvider;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import jakarta.json.stream.JsonGenerator;
import jakarta.json.stream.JsonParser;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.List;
import org.junit.Test;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.jsonb.JsonbJsonpMapper;
import org.opensearch.client.opensearch.core.SearchRequest;

import java.io.StringReader;
import java.io.StringWriter;
import java.util.List;

import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class InnerHitsTest {
private JsonpMapper mapper = new JsonbJsonpMapper();
private String storedSalary = "details.salary";
private String storedJobId = "details.jobId";
private final JsonpMapper mapper = new JsonbJsonpMapper();
private final String storedSalary = "details.salary";
private final String storedJobId = "details.jobId";

/**
* test if the json field for storedFields is generated with the correct name "stored_fields"
Expand All @@ -44,7 +42,6 @@ public void testInnerHitFromParsed() {
String actualJson = toJson(innerHits);
assertEquals(innerHitsJson, actualJson);


}

/**
Expand All @@ -68,13 +65,11 @@ private String toJson(JsonpSerializable obj) {
}
return stringWriter.toString();
}
private String innerHitsJson = String.format(
"{\"_source\":false,\"stored_fields\":[\"%s\",\"%s\"]}",
storedJobId,
storedSalary

private final String innerHitsJson = String.format("{\"_source\":false,\"stored_fields\":[\"%s\",\"%s\"]}", storedJobId, storedSalary);
private final String searchRequestJson = String.format(
"{\"_source\":false,\"query\":{\"bool\":{\"must\":[{\"match_all\":{}},{\"nested\":{\"inner_hits\":%s,\"path\":\"details\","
+ "\"query\":{\"match_all\":{}}}}]}},\"stored_fields\":[\"title\",\"companyName\"]}",
innerHitsJson
);
private String searchRequestJson = String.format(
"{\"_source\":false,\"query\":{\"bool\":{\"must\":[{\"match_all\":{}},{\"nested\":{\"inner_hits\":%s,\"path\":\"details\","
+ "\"query\":{\"match_all\":{}}}}]}},\"stored_fields\":[\"title\",\"companyName\"]}",
innerHitsJson);
}
Loading