spring-projects/spring-data-elasticsearch — pull request #27 by lbroudoux (2013-11-15 00:18:00+00:00)
Title: Adding support for letting Elasticsearch generate Id for document

Hello,

in the following of issue #21, I've made the suggested modifications to allow to index document that have not yet an Id. This way, Elasticsearch will auto-generate an id. For that, I use the `client.prepareIndex()` method as explained here : http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/index_.html#index-doc

Having this auto-generated id used as document id is in fact a bit trickier that I've thought at first. ES is storing it as `_uid` so that it can be used for later retrieving by id (no problem) but still consider given `id` field of document as null. As a consequence, an extra operation for setting the @Id annoted field of document to the generated id is necessary when mapping the results of a query.

I've added tests to template and repository to ensure nothing is broken and that this new feature behaves as expected. Hope this helps. Let me know if some adaptations or more work for integration need to be done.

I've implemented this cause I needed it in the context of a Spring Roo Elasticsearch layer plugin (see https://github.com/lbroudoux/spring-roo-addon-layers-repository-elasticsearch) that aim to bring the features already available in the Spring Roo Mongodb layer.

Best regards,
--
Laurent