【发布时间】: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