spring-data-elasticsearch icon indicating copy to clipboard operation
spring-data-elasticsearch copied to clipboard

NoSuchIndexException - throw instead of catch

Open CallMeSweets opened this issue 2 years ago • 3 comments

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.

CallMeSweets avatar May 10 '22 14:05 CallMeSweets

will have a look this evening - might be that this behaviour already is changed when integrating the new client.

sothawo avatar May 12 '22 05:05 sothawo

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).

sothawo avatar May 12 '22 19:05 sothawo

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

CallMeSweets avatar May 13 '22 08:05 CallMeSweets

This was fixed with #2389, now both the imperative and reactive code now throw a org.springframework.data.elasticsearch.NoSuchIndexException.

sothawo avatar Feb 01 '23 18:02 sothawo