Elasticsearch with Rails - 在2.2版本中映射`_all`字段

时间:2016-05-04 11:53:05

标签: ruby-on-rails elasticsearch

我进行了多模型搜索,我的配置如下:

settings analysis: {
  ...
} do
  mappings do
    indexes "_all",
      type: "string",
      analyzer: "ngram_analyzer",
      search_analyzer: "whitespace_analyzer"
  end
end

这一切在Elasticsearch 2.1上都运行良好,但在2.2中打破了:

Elasticsearch::Transport::Transport::Errors::BadRequest: [400]
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "Failed to parse mapping [insurer]: Field [_all] is defined twice in [insurer]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [insurer]: Field [_all] is defined twice in [insurer]",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Field [_all] is defined twice in [insurer]"
    }
  },
  "status": 400
}

如何修复它以索引2.2中的all字段?

1 个答案:

答案 0 :(得分:0)

好的,事实证明我需要将映射更改为:

settings analysis: {
  ...
} do
  mappings _all: {
    type: "string", analyzer: "ngram_analyzer", search_analyzer: "whitespace_analyzer"
  }
end

现在效果很好。