首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails:不能映射类型:完成(Gem: elasticsearch-model)

Rails:不能映射类型:完成(Gem: elasticsearch-model)
EN

Stack Overflow用户
提问于 2016-08-05 16:44:28
回答 1查看 39关注 0票数 1

下面是我的ActiveRecord定义

代码语言:javascript
复制
  settings index: { number_of_shards: 1, number_of_replicas: 0 } do
    mappings  do
      indexes :cas, type: 'string', index: "not_analyzed", analyzer: 'snowball'
      indexes :names, type: 'string', analyzer: 'snowball'
      indexes :names_cn, type: 'string', analyzer: 'ik_max_word'
      indexes :suggest, type: 'completion', analyzer: 'snowball'
      indexes :suggest_cn, type: 'completion', analyzer: 'ik_max_word'
    end
  end

  def as_indexed_json(options = {})
    {
      cas: self.cas.to_s.strip,
      names: self.suggests,
      names_cn: self.suggests_cn,
      suggest: { input: self.suggests },
      suggest_cn: { input: self.chinese_keywords }
    }
  end

这就是elasticsearch服务器向我展示的内容

代码语言:javascript
复制
{
  "something-development": {
    "aliases": {},
    "mappings": {
      "chemicals": {
        "properties": {
          "cas": {
            "type": "string"
          },
          "names": {
            "type": "string"
          },
          "names_cn": {
            "type": "string"
          },
          "suggest": {
            "properties": {
              "input": {
                "type": "string"
              }
            }
          },
          "suggest_cn": {
            "properties": {
              "input": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1470383173607",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "a8ONu0WSRGuImjLRU6ddVg",
        "version": {
          "created": "2030499"
        }
      }
    },
    "warmers": {}
  }
}

我认为suggest & suggest_cn项的行为应该是这样的:类型完成

代码语言:javascript
复制
suggest": {
  "type": "completion",
  "analyzer": "snowball",
  "payloads": false,
  "preserve_separators": true,
  "preserve_position_increments": true,
  "max_input_length": 50
}

也许我在理解这一点上有一些问题。任何人都能帮上忙(最好的祝福)

https://github.com/elastic/elasticsearch-rails/issues/612和我也有一个问题。

EN

回答 1

Stack Overflow用户

发布于 2016-08-09 10:19:08

使用Chemical.__elasticsearch__.create_index! force: true

代替Chemical.__elasticsearch__.client.indices.create index: Chemical.index_name

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38784964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档