【问题标题】:How do you use the ingest-attachment plugin with elasticsearch-rails?您如何将摄取附件插件与 elasticsearch-rails 一起使用?
【发布时间】:2017-04-22 22:52:22
【问题描述】:

我以前使用的 mapper-attachments 插件现在已弃用,它与普通索引一起使用相当容易。现在 ingest-attachment 已经取代了它并需要管道等。如何正确使用它变得令人困惑。

假设我有一个名为Media 的模型,它有一个包含base64 编码文件的file 字段。我在该文件中有以下映射:

mapping '_source' => { :excludes => ['file'] } do
  indexes :id, type: :long, index: :not_analyzed
  indexes :name, type: :text
  indexes :visibility, type: :integer, index: :not_analyzed
  indexes :created_at, type: :date, include_in_all: false
  indexes :updated_at, type: :date, include_in_all: false

  # attachment specific mappings
  indexes 'attachment.title', type: :text, store: 'yes'
  indexes 'attachment.author', type: :text, store: 'yes'
  indexes 'attachment.name', type: :text, store: 'yes'
  indexes 'attachment.date', type: :date, store: 'yes'
  indexes 'attachment.content_type', type: :text, store: 'yes'
  indexes 'attachment.content_length', type: :integer, store: 'yes'
  indexes 'attachment.content', term_vector: 'with_positions_offsets', type: :text, store: 'yes'
end

我已经通过 curl 创建了一个附件管道:

curl -XPUT 'localhost:9200/_ingest/pipeline/attachment' -d'
{
  "description" : "Extract attachment information",
  "processors" : [
    {
      "attachment" : {
        "field" : "file"
      }
    }
  ]
}'

现在,以前一个简单的Media.last.__elasticsearch__.index_document 就足以通过mapper-attachments 插件将记录与实际的file 一起索引。

我不确定如何使用管道和 elasticsearch-rails gem 来处理 ingest-attachment

我可以通过 curl 执行以下 PUT:

curl -XPUT 'localhost:9200/assets/media/68?pipeline=attachment' -d'
{ "file" : "my_really_long_encoded_file_string" }'

这将索引编码文件,但显然它不会索引模型的其余数据(或者如果它之前被索引,则完全覆盖它)。我真的不想在 curl 命令中包含每个模型属性以及文件。有没有更好或更简单的方法来做到这一点?我是否完全没有管道并且摄取应该工作?

【问题讨论】:

  • 你能显示完整的代码吗?我在 Rails 项目中设置摄取插件时遇到问题。

标签: ruby-on-rails elasticsearch elasticsearch-rails elasticsearch-5 elasticsearch-model


【解决方案1】:

终于想通了。我需要更新 ES gems,特别是 elasticsearch-api。

根据我的映射和管道设置,您可以轻松做到:

Media.last.__elasticsearch__.index_document pipeline: :attachment

Media.last.__elasticsearch__.update_document pipeline: :attachment

这将正确索引所有内容,并且您的文件将通过摄取管道正确解析和索引。

【讨论】:

    猜你喜欢
    • 2017-06-25
    • 2018-06-03
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 2017-06-18
    • 2018-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多