加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 带有字段的Rails ElasticSearch模型

发布时间:2020-12-16 19:08:01 所属栏目:百科 来源:网络整理
导读:我正在使用 elasticsearch-rails和 mongoid 我有以下简单的字段映射: "title": { "type": "string","fields": { "raw": { "type": "string","index": "not_analyzed" } } } 我的模型看起来像这样: class ArticlesEventinclude Mongoid::Documentinclude El
我正在使用 elasticsearch-rails和 mongoid
我有以下简单的字段映射:
"title": {
              "type": "string","fields": {
                 "raw": {
                    "type": "string","index": "not_analyzed"
                 }
              }
           }

我的模型看起来像这样:

class ArticlesEvent
include Mongoid::Document
include Elasticsearch::Model

field :title,type: String

attr_accessible :title

def as_indexed_json(options={})
  as_json(except: [:id,:_id])
end

任何人都可以举例说明如何使用title.raw字段定义rails模型,以及如何访问该字段?由于多字段已被弃用,因此很难找到使用rails和mongoid的工作示例.

谢谢

解决方法

您应该能够在模型中使用以下属性定义来实现此目的:
attribute :title,String,mapping: { 
    fields: {
       raw:  { type: 'string',index: 'not_analyzed' }
    } 
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读