如何防止单个字段存储在_source中

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

我有一个模型可以通过 Hibernate Search 5.6.5 和 Elasticsearch 2.4.6 进行搜索。

@Entity
@Indexed
class Model {

     @Field
     String normalField;

     @Field
     @Lob
     String reallyBigField;
}

我不想让 Elasticsearch 存储 reallyBigField。 Hibernate Search 提供了 @Field(store = Store.NO) 属性,但它是默认的,并且看起来 Elasticsearch 将处理 store-属性 与 Lucene 不同(Lucene 不存储任何东西,Elasticsearch 有单独的源-商店).

使用Store.NO 禁用字段级别的存储。在我们当前的搜索 5.x Elasticsearch 集成中并未真正使用的字段级存储。

你说得对,Elasticsearch 将内容额外存储在一个单独的 _source 字段中,这就是我们现在在 Hibernate Search 中用于投影的字段(由于 Elasticsearch 的一些限制 - 我们可能会做得更好将来)。

您可以通过修改映射 https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html#include-exclude 来禁用 _source 中的这个特定字段。但我们不支持开箱即用,因此您必须手动完成。

该解决方案可能基于 JsonViews,以便配置 ElasticSearch 的映射器忽略一些标有另一个视图的字段,这些字段可能用于剩余输出: