【问题标题】:ElasticSearch Rails - Setting a Custom AnalyzerElasticSearch Rails - 设置自定义分析器
【发布时间】:2014-10-05 03:47:05
【问题描述】:

我通过 elasticsearch-rails (https://github.com/elasticsearch/elasticsearch-rails) 在 Rails 4 中使用 ElasticSearch

我有一个带有 email 属性的 User 模型。

我正在尝试使用文档中描述的“uax_url_email”标记器:

class User < ActiveRecord::Base
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

  settings analysis: { analyzer: { whole_email: { tokenizer: 'uax_url_email' } } } do
    mappings dynamic: 'false' do
      indexes :email, analyzer: 'whole_email'
    end
  end

end

我按照 wiki (https://github.com/elasticsearch/elasticsearch-rails/wiki) 和 elasticsearch-model 文档 (https://github.com/elasticsearch/elasticsearch-rails/wiki) 中的示例进行操作。

它不起作用。如果我直接查询elasticsearch:

curl -XGET 'localhost:9200/users/_mapping

返回:

{
  "users": {
    "mappings": {
      "user": {
        "properties": {
          "birthdate": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "created_at": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "email": {
            "type": "string"
          },
          "first_name": {
            "type": "string"
          },
          "gender": {
            "type": "string"
          },
          "id": {
            "type": "long"
          },
          "last_name": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "role": {
            "type": "string"
          },
          "updated_at": {
            "type": "date",
            "format": "dateOptionalTime"
          }
        }
      }
    }
  }
}

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 elasticsearch elasticsearch-plugin


    【解决方案1】:

    这最终成为我如何创建索引的问题。我正在尝试:

    User.__elasticsearch__.client.indices.delete index: User.index_name
    User.import
    

    我希望这会删除索引,然后重新导入值。但是我需要这样做:

    User.__elasticsearch__.create_index! force: true
    User.import
    

    【讨论】:

    • 天哪,这随机救了我的命。完全不知道为什么某些记录没有被导入。坦率地说,我仍然不是 100% 确定为什么会这样,但只是在没有索引删除的情况下执行 User.import 不会。
    猜你喜欢
    • 2014-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多