在我的项目中,我使用mapper-attachments插件将数据存储在活动记录模型中并在弹性搜索中索引 html 文档。我的文档映射如下所示:
include Elasticsearch::Model
settings index: { number_of_shards: 5 } do
mappings do
indexes :alerted
indexes :title, analyzer: 'english', index_options: 'offsets'
indexes :summary, analyzer: 'english', index_options: 'offsets'
indexes :content, type: 'attachment', fields: {
author: { index: "no"},
date: { index: "no"},
content: { store: "yes",
type: "string",
term_vector: "with_positions_offsets"
}
}
end
end
我运行查询以仔细检查我的文档映射和结果:
"mappings": {
"feed_entry": {
"properties": {
"content": {
"type": "attachment",
"path": "full",
"fields": {
"content": {
"type": "string",
"store": true,
"term_vector": "with_positions_offsets"
},
它工作得很好(上面的类型:'附件')。我可以完美地通过 html doc 进行搜索。
我的 mysql 的 activerecord 存在性能问题,我真的不需要将它存储在数据库中,所以我决定迁移到存储在 elasticsearch 中。
我正在使用elasticsearch-persistence gem 进行实验。
我将映射配置如下:
include Elasticsearch::Persistence::Model
attribute :alert_id, Integer
attribute :title, String, mapping: { analyzer: 'english' }
attribute :url, String, mapping: { analyzer: 'english' }
attribute :summary, String, mapping: { analyzer: 'english' }
attribute :alerted, Boolean, default: false, mapping: { analyzer: 'english' }
attribute :fingerprint, String, mapping: { analyzer: 'english' }
attribute :feed_id, Integer
attribute :keywords
attribute :content, nil, mapping: { type: 'attachment', fields: {
author: { index: "no"},
date: { index: "no"},
content: { store: "yes",
type: "string",
term_vector: "with_positions_offsets"
}
}
但是当我对映射进行查询时,我得到了这样的结果:
"mappings": {
"entry": {
"properties": {
"content": {
"properties": {
"_content": {
"type": "string"
},
"_content_type": {
"type": "string"
},
"_detect_language": {
"type": "boolean"
},
这是错误的。谁能告诉我如何使用附件类型进行映射?
非常感谢您的帮助。