spring-data-elasticsearch
spring-data-elasticsearch copied to clipboard
NoSuchIndexException - throw instead of catch
Hi, In ReactiveElasticsearchTemplate.class there are such a methods like:
- protected Mono<Long> doCount(SearchRequest request)
- protected Flux<SearchDocument> doScroll(SearchRequest request)
- protected Flux<SearchDocument> doFind(SearchRequest request) That methods catch NoSuchIndexException when index not exists and return Mono.empty(). Is it not better solution to throw such a exception? Because it might be really difficult to guess what the real problem is when we get empty data from elastic when the real problem is wrong index name and there is no information in logs.
will have a look this evening - might be that this behaviour already is changed when integrating the new client.
ok, that's not changed.
The question now is: what is the desired behaviour? When I look at what Elasticsearch returns: Both cases - searching something in a non-existent index and searching something that does not exist in an existing index return a 404 (not found).
Being consistent with Elasticsearch would mean to not change the behaviour. I will need to have a deeper look and compare to what the imperative implementation does. If we change this to not map the exception would mean a breaking change, and this would then be included in version 5. There is still a lot of time until that will be released, so I will just keep this ticket open to have a deeper look when I find the time (I currently am quite busy, so bear with me).
Hi, In the imperative solution, there is no such an exception as "NoSuchIndexException". If the index does not exist there is just thrown exception that might be caught in a higher layer of the code.
The desired behavior: Just throw an exception instead of catching it to give a possibility to catch that exception in the higher layer of the code. That will give a possibility to have pieces of information that index not exist instead of returning Mono.empty().
Don't worry this is not so important at this moment, but for sure might create some problems for developers in the future.
Thanks for the answer, cheers
This was fixed with #2389, now both the imperative and reactive code now throw a org.springframework.data.elasticsearch.NoSuchIndexException
.