繁体   English   中英

ElasticSearch with Tire不包含STI模型的自定义分析器

[英]ElasticSearch with Tire doesn't include custom analyzer with STI model

我有一个STI模型,希望可以用ElasticSearch和Tire搜索。 我遇到的问题是,当Tire创建映射时,它似乎忽略了第二个模型的自定义分析器。 以下是我的模型的示例。

class Account < ActiveRecord::Base
  attr_accessible :name, :type

  include Tire::Model::Search
  include Tire::Model::Callbacks

  tire.settings :analysis => {
          :analyzer => {
          "custom_search_analyzer" => {
              "tokenizer" => "keyword",
              "filter" => "lowercase"
          },
          "custom_index_analyzer" => {
              "tokenizer" => "keyword",
              "filter" => ["lowercase","substring"]
          }
      },
      :filter => {
          :substring => {
              "type" => "nGram",
              "min_gram" => 1,
              "max_gram" => 20
          }
      }
  } do
    mapping do
      indexes :id, :type => 'integer', :include_in_all => false
      indexes :name, :type => 'string', :search_analyzer => :custom_search_analyzer,     :index_analyzer=>:custom_index_analyzer
    end
  end

  def to_indexed_json
    hash = {}
    hash[:id] = id
    hash[:name] = name
    hash.to_json
  end
end

class StandardAccount < Account
  tire.index_name 'accounts'
end

class SuperAccount < Account
  tire.index_name 'accounts'
end

当我通过rake任务或通过创建模型来创建轮胎索引时,它会创建映射,但是对于继承的模型,它不会将自定义分析器应用于它们。 如果我看一下使用

curl -XGET 'http://127.0.0.1:9200/accounts/_mapping?pretty=1'  

我得到:

{
  "accounts" : {
    "account" : {
      "properties" : {
        "id" : {
          "type" : "integer",
          "include_in_all" : false
        },
        "name" : {
          "type" : "string",
          "index_analyzer" : "custom_index_analyzer",
          "search_analyzer" : "custom_search_analyzer"
        }
      }
    },
    "standard_account" : { 
      "properties" : {
        "id" : {
          "type" : "long"
        }
        "name" : {
          "type" : "string"
        }
      }
    },
    "super_account" : {
      "properties" : {
        "id" : {
          "type" : "long"
        }
        "name" : {
          "type" : "string"
        }
      }
    }
  }
}

即使我将映射声明移到继承的类上,它似乎也只是创建的第一个使用额外选项的模型。 我可以通过ElasticSearch手动创建索引,但是想知道是否有办法用Tire做到这一点? 还是我设置不正确

您可能已经找到了答案,但是我认为这可能对您或其他有相同问题的人有所帮助:

https://stackoverflow.com/a/13660263/1401343

-弗拉德

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM