簡體   English   中英

ElasticSearch Rails-設置自定義分析器

[英]ElasticSearch Rails - Setting a Custom Analyzer

我正在通過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"
          }
        }
      }
    }
  }
}

這最終成為我如何創建索引的問題。 我正在嘗試:

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

我希望這會刪除索引,然后重新導入值。 但是我需要做:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM