带有Tyre的ElasticSearch不包含带有STI模型的自定义分析器 [英] ElasticSearch with Tire doesn't include custom analyzer with STI model

查看:60
本文介绍了带有Tyre的ElasticSearch不包含带有STI模型的自定义分析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an STI model which I want to be searchable with ElasticSearch and Tire. The issue I am having is when Tire creates the mappings it seems to ignore my custom analyzers for the second model. Below is an example of my models.

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任务或通过创建模型通过轮胎创建索引时,它会创建映射,但对于继承的模型,它不会将自定义分析器应用于它们.如果我使用

When I create the index through tire, either with the rake task or through creating a model it creates the mappings but for the inherited models it doesn't apply the custom analyzers to them. If I look at the mappings using

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做到这一点?还是我的设置不正确

Even if I move the mapping declarations to the inherited classes it seems to be only the first model created that picks up the extra options. I can manually create the indexes through ElasticSearch but was wondering if there was a way to do it with Tire? Or do I have something set up incorrectly

推荐答案

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

You might have figured out the answer already, but I think this might help you, or others having the same problem:

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

-弗拉德

这篇关于带有Tyre的ElasticSearch不包含带有STI模型的自定义分析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆