【问题标题】:index file content in elasticsearch without storing the actual content in base64在elasticsearch中索引文件内容而不将实际内容存储在base64中
【发布时间】:2017-05-27 14:12:50
【问题描述】:

我正在使用 elasticsearch .net NEST 库来索引数据和文件内容。 我使用映射器附件来索引文件内容。 弹性搜索以 base64 编码存储文件内容。 我已经在文件系统上存储了文件,所以我不想再弹性搜索存储。

是否可以在不实际存储文件内容的情况下使用 .Net NEST 来索引文件内容。

我尝试了什么: 试图设置 [ElasticProperty(Type = FieldType.Attachment, Store = false)] 但是弹性搜索仍然会存储内容并增加索引大小

【问题讨论】:

  • 你使用的是什么版本的 Elasticsearch 和什么版本的 NEST?我写了一篇关于使用 Elasticsearch 和 NEST for 5.x 处理附件的博客文章,希望对您有所帮助:elastic.co/blog/…

标签: c# elasticsearch nest elasticsearch-plugin


【解决方案1】:

默认情况下,字段值为indexed 以使其可搜索,但它们不存储

正如here所解释的那样。

这意味着在大多数情况下,通常不需要设置Store = false。您仍然在 Elasticsearch 中看到该文档的原因是:

_source 字段包含在索引时传递的原始 JSON 文档正文。

您需要做的是避免这种情况disable the _source field,尽管通常建议您不要这样做,因此请确保这是您想要的,并阅读“在禁用 _source 字段之前考虑”部分。

有多种方法可以禁用 _source 字段(模板、映射),但假设您使用 NEST 创建索引,您可以执行以下操作(我假设您正在使用v1.x of NEST 给定您尝试使用的属性):

client.CreateIndex(
    idxDescriptor => idxDescriptor.AddMapping<TModel>(
        mappingDescriptor => mappingDescriptor.SourceField(source => source.Enabled(false))))

注意:如果您这样做,索引大小仍会增加,因为需要对字段进行索引才能使其可搜索。

【讨论】:

  • Eitamal 我已经尝试了上面的这段代码,但文件内容仍然存储在 elasticsearch 节点中。我想要的不是将实际文件内容存储到 elasticsearch 节点,我已经将文件存储在我的系统上。
猜你喜欢
  • 2020-07-10
  • 2010-09-17
  • 1970-01-01
  • 2018-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-27
  • 2010-11-07
相关资源
最近更新 更多