I need to store byte array field in Elasticsearch without indexing it. I'm using spring data elasticsearch module. What is the right way? Thanks
1 Answer
The correct fieldtype in Elasticsearch for this would be the binary field type. Alas this is currently not available in Spring Data Elasticsearch, I just created a Jira issue for this.
Even if the binary field type were implemented, you still would need to base64 encode the binary data, so that in Elasticsearch it would be stored in a text representation.
Until this binary field type is implemented, you might try to use a field definition like:
@Field(type = FieldType.Keyword, index = false)
private String base64Data;
Like with the binary field type you have to encode your data as base64 String and decode it when it's coming back from the search. Even better wer if you could add the doc_values=false argument to @Field annotation, to have support for this, there is currently a PullRequest open, but which is not yet ready to be merged; not sure, if this will make it into the 3.2.0 release.
Edit March 2020:
in version 4.0.0, you can user the FieldType.Binary type together with a byte[] and this will be converted to a base64 encoded string (and back again).