Closed royteeuwen closed 4 years ago
Pinging @elastic/es-search (:Search/Search)
Pinging @elastic/es-core-features (:Core/Features/Java High Level REST Client)
heya, at first glance the response you are trying to parse cannot be parsed by the high level REST client as it requires the typed_keys
parameter set to true
. That way the response will contain the same suggestion, but its name will be composed of the name of the suggestion as well as its type separated by #
. This way the parser knows which class to create for that type of suggestion.
Hey @javanna , how is it possible then that I actually got that response first by using the high level client to get it? Thats how I created the mock json to test, by first using the real logic and saving the SearchResponse.toString() in a test resource file
toString calls toXContent. You should call toXContent manually and provide the typed_keys param to it. Even if you are printing a response obtained through the client, you still need to print it out the same way that the client expects it or it cannot be parsed. Otherwise the client does not know which class to create.
On Fri, May 29, 2020, 21:54 Roy Teeuwen notifications@github.com wrote:
Hey @javanna https://github.com/javanna , how is it possible then that I actually got that response first by using the high level client to get it? Thats how I created the mock json to test, by first using the real logic and saving the SearchResponse.toString() in a test resource file
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/elastic/elasticsearch/issues/57297#issuecomment-636158926, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGLHTFMOFEEIEZ4KHCCDILRUAHFPANCNFSM4NNFPKLQ .
hi @royteeuwen I hope you don't mind if I close this issue given that it's not a bug.
Hey @javanna, sorry I have two days off so couldnt test it out yet. I still dont see how to call the toxcontent manually so that its parseable afterwards. Can you provide an example?
@royteeuwen an example is here: https://github.com/elastic/elasticsearch/blob/master/server/src/test/java/org/elasticsearch/action/search/SearchResponseTests.java#L157 .
Elasticsearch version 7.7.0
Plugins installed: /
JVM version (
java -version
): 11.0.6OS version (
uname -a
if on a Unix-like system): macOS Catalina / Redhat 7Description of the problem including expected versus actual behavior:
I am trying to create unit tests for classes that use the java high level rest client. To make this easier I am mocking the response that is given by elasticsearch so that all the business logic that happens can then be tested without an actual running elasticsearch. The problem is that this mocking is not working.
A sample query to Elasticsearch that we are testing:
A sample rest response of Elasticsearch:
Parsing the SearchResponse from the JSON string:
Exception being thrown:
What would be a correct / good way to make this work? All our integration tests with a suggest in json response are failing because of this.