With the repository approach it may not be possible without the models. Having said that , the other way is to use the HTTP API using webflux to approach this problem.
As an example , I have set up a sample index with some data including an employee that matches this name
curl -XPOST "http://localhost:9200/_search" -H 'Content-Type: application/json' -d'{"query": {"match": {"name":"JohnSmith77067"}}}' |jq
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 3.205453,
"hits": [
{
"_index": "sample",
"_type": "employee",
"_id": "KbxD6IEBCsN8USu280mF",
"_score": 3.205453,
"_source": {
"id": null,
"organization": {
"id": 31,
"name": "TestO31",
"address": "Test Street No. 31"
},
"department": {
"id": 3631,
"name": "TestD3631"
},
"name": "JohnSmith77067",
"age": 66,
"position": "Developer"
}
}
]
}
}
will try and emulate this through a free query run through reactive web client
@RestController
@RequestMapping("/employees")
public class EmployeeController {
private static final Logger LOGGER = LoggerFactory.getLogger(EmployeeController.class);
private final WebClient client = WebClient.create();
@PostMapping("/customselect")
public Mono<String> generateMulti() throws URISyntaxException {
return client.post().uri(new URI("http://localhost:9200/_search")).
accept(MediaType.APPLICATION_JSON).
header("Content-Type", "application/json").
body(Mono.just("{\"query\": {\"match\": {\"name\":\"JohnSmith77067\"}}}"), String.class)
.retrieve()
.bodyToMono(String.class);
}
}
starting the app up and then hitting the endpoint will return similar results You could pass a custom query in the body , but you get the idea of this.
[![Postman results][1]][1]
Having a repository based approach takes away all the boilerplate and provides a lot of goodies & error handling through config driven approaches. Having said that if that does not suit , for ES the way would be to use the raw HTTP API (there are many things you could attach to the web clients such as Auth , timeout etc that i have done) and then take it from there. Hope this helps a bit
[1]: https://i.stack.imgur.com/FIAXR.png