Custom SQL to Index Documents

I would like to utilize raw SQL to index documents. So rather than just indexing the document from the model, I need to be able to query the model and join it with other tables to create an index with additional fields for each document indexed. For instance, if I have a books table and a readers table, I want to index the book model along with an array of readers associated with that book. I am doing this inside my application, but need to be able to populate the index at any time, reindex etc., with sql that does the same thing for an entire data set.

Can I do this with elasticsearch? In sphinx I did this setting datasources (sql statements) for the indexing which would be utilized on indexing and re-indexing.

Thank you for your kind assistance in advance with this.

If you are using Java and Hibernate, the latest version of HSearch has now a connection to Elasticsearch.

Might help.