10

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

我有一个带有电子邮件属性的用户模型。

我正在尝试使用文档中描述的“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"
          }
        }
      }
    }
  }
}
4

1 回答 1

15

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

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

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

User.__elasticsearch__.create_index! force: true
User.import
于 2014-08-12T07:53:09.317 回答