How would I go about customizing the document that Hibernate Search ultimately writes?
I need to use the Percolate feature of Elasticsearch to identify documents in my search index. Probably best to read the Elasticsearch documentation to understand how this works. In my case, this means that I need a few things.
- Additional entries in the index mapping. One for a field of type “percolator” that contains the query and one to contain the mapping information of the virtual document to be created during the query execution.
- The ability to supply a value for the field of type “percolator” in the documents that get written to the index
- A means of executing the percolate query
In my case, since I am not using the index management features of Hibernate Search, I am able to create my own index mappings so item 1 is not an issue for me. Also, because I am trying to use Elasticsearch as natively in my code as possible, I am not using Hibernate Search query building and instead am writing the native Elasticsearch queries in my codebase, so item 3 is not an issue for me.
However, I have not found a solution for item 2 in that I have not found a way to customize the document Hibernate Search creates when writing the document to Elasticsearch. One thing I thought about doing was adding properties to my entity but wasn’t sure how to keep those properties from being persisted to my relational database while still having them be written to Elasticsearch. Also, for my case, the value of the percolate field is calculated depending on values of other properties of the entity and how it is calculated is based on the entity type.
Ideally i would like to be able to supply a means on a per entity basis that would allow me to manipulate the document that is written to Elasticsearch and not sure if this is possible.
I am using the Hibernate Search 6.0 Beta