Hello,
for a use-case I'm creating I want to build a SearchResponse similar to a response which did not retrieve any matched documents.
co.elastic.clients.elasticsearch.core.SearchResponse.of(r -> r
.aggregations(ApiTypeHelper.undefinedMap())
.suggest(ApiTypeHelper.undefinedMap())
.fields(ApiTypeHelper.undefinedMap())
.timedOut(false)
.hits(h -> h.total(t -> t.value(0).relation(TotalHitsRelation.Eq))
.hits(ApiTypeHelper.undefinedList()))
.shards(s -> s.total(1).failed(0).successful(1))
.took(0));
However when building the response as shown above an exception: co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'HitsMetadata.hits' will be thrown. According to MissingRequiredPropertyException in a response | Elasticsearch Java API Client [8.13] | Elastic this is due to the properties missing not being optional. However checking an actual 0 documents matched response from ES I did not see the missing properties either which are "id" and "index". After defining the properties "id" and "index" I am able to build the object however it then differs from the actual object parsed from the real ES zero result response.
Maybe I overlooked some utility functions that are designed for this use-case.
Thanks in advance!
Best Regards
Sven