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

Fix `convertId` and `stringIdRepresentation` usage in template and repository classes.

Open sothawo opened this issue 2 years ago • 3 comments

These two methods are used inconsistently, it seems that not all requests do a proper conversion of an ID but only a string representation - for example when indexing an entity with a custom id class, the toString() representation is used for the document id in Elasticsearch.

sothawo avatar Jul 18 '22 19:07 sothawo

Good time of the day!

I would like to work on solving this problem, can you please provide some guide lines about where better to start from?

Thank you in advance !

Nik9695 avatar Jul 27 '22 13:07 Nik9695

Hello, great that you want to help out.

This issue is some internal refactoring thing I came across recently. It's about the conversion of the id of an entity (which might be any class) to a String when issuing a call to Elasticsearch.

There are currently two functions used for this:

  • org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter#convertId(Object)
  • org.springframework.data.elasticsearch.core.ElasticsearchOperations#stringIdRepresentation(Object)

The first one is the one that should be used, as this uses the conversion service in he ElasticsearchConverter. If you have a custom id class I and register a converter from String> to I~ and back, these converters should be used.

So basically what would be needed for this ticket (imperative, non reactive code):

  • add a String convertId(Object o) method to the ElasticsearchOperations interface, this could as a default implementation call the convertId() method of it's converter.
  • deprecated the stringIdRepresentation method with a reference to the new method.

Is this enough information to get you started?

sothawo avatar Jul 30 '22 14:07 sothawo

Thank you for such good guide lines.

For now I think that is enough. I will start and probably after I will have something to ask.

Thank you!

Nik9695 avatar Jul 31 '22 08:07 Nik9695

Hi @Nik9695, any progress on this?

sothawo avatar Sep 19 '22 16:09 sothawo