Search code examples
elasticsearchhibernate-search

How to prevent a single field to be stored in the _source


I have a model made searchable through Hibernate Search 5.6.5 and Elasticsearch 2.4.6.

@Entity
@Indexed
class Model {

     @Field
     String normalField;

     @Field
     @Lob
     String reallyBigField;
}

I don't want Elasticsearch to store the reallyBigField. Hibernate Search provides the @Field(store = Store.NO) property, but it is default and it appears, that Elasticsearch will handle the store-property differently than Lucene (Lucene is not storing anything, Elasticsearch has the separate source-store).


Solution

  • Using Store.NO disables the storage at the field level. Storage at the field level which is not really used in our current Search 5.x Elasticsearch integration.

    You're right that Elasticsearch additionally stores the content in a separate _source field and this is the one we use for projections in Hibernate Search right now (due to some limitations of Elasticsearch - we might do better in the future).

    You can disable this particular field in _source by modifying the mapping: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html#include-exclude . But we don't support it out of the box so you have to do it manually.