I want to use the following elastic search query in Java to search through all my documents in my index.
{
"query": {
"query_string": {
"query": "my search input"
}
}
}
When I use CURL it works fine and i get results back, but when i try to use this query in Java, it complains and gives me the following exception:
co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [parsing_exception] unknown query [query]
This is what my code looks like in Java:
@GetMapping("/search")
public void searchResume(@RequestParam(name = "search") String query) {
Query q = new StringQuery("""
{
"query": {
"query_string": {
"query": "my search input"
}
}
}
""");
System.out.println(operations.search(q, Resume.class));
}
Does someone know why it works using CURL but does not work when using Java and spring-data-elasticsearch?
I tried googling a lot and even asked chatgpt for help but I can't seem to find out why it doesn't work. Thank you in advance.