簡體   English   中英

輪胎中的自定義分析器(ElasticSearch)

[英]Custom Analyzer in Tire (ElasticSearch)

我正在嘗試創建此自定義分析器,由於某種原因,我得到的Analyzer [] not found for field []錯誤...我四處查看並嘗試了不同的實現,並且我認為它具有正確的語法。 。 這里是:

settings :number_of_shards => 5,
         :number_of_replicas => 2,
         :analysis => {
           :analyzer => {
             :ticker_analyzer => { 
               "type"      => 'custom',
               "tokenizer" => 'ticker_pattern',
               "filter"    => [ 'word_delimiter_filter', 'standard' ]
             }
           },
           :filter => {
             :word_delimiter_filter => {
               "type"                => 'word_delimiter',
               "preserve_original"   => true
             }
           },
           :tokenizer => {
             :ticker_pattern => {
               "type"      => 'pattern',
               "pattern"   => '\w+'
             }
           }
         } do
  mapping do
    # ... some more indexes that work fine, with regular analyzers
    indexes :company_ticker,      type: 'string',   boost: 5.0,   analyzer: 'ticker_analyzer',  as: 'index_company_ticker'
  end
end

所以我得到錯誤Analyzer [ticker_analyzer] not found for field [company_ticker]

有什么想法嗎?

另外,我看到了一些示例,這些示例不需要將塊傳遞給settings選項。 我只需要關閉settings然后再定義mapping ,就可以了嗎? (我已經在其他人發布代碼段的地方看到了這一點...)

謝謝!

-弗拉德

好的,這就是我遇到的實際問題,為什么它不起作用。
這是因為我試圖創建一個索引,該索引將使用該模型的映射(我不是試圖進行Model.create_elasticsearch_index),而是使用類似

index = Tire::Index.new('swap_index')
index.create(:mappings => MyModel.tire.mapping_to_hash)
index.import(mymodel_entries)
# and then do some swapping between the old index and the new one, through alias'es

好吧,問題在於我沒有將settings傳遞給新索引。 我只是將MyModel的mappings傳遞給它,而沒有將settings傳遞給它。 所以,正確的方法是

index.create(:settings => MyMode.tire.settings, :mappings => MyModel.tire.mapping_to_hash)

這解決了我遇到的錯誤。

(我的示例在我的情況下仍然無法使用,因為分析儀可能因我的情況而損壞,但我只是想為可能有類似問題的用戶提供幫助)

謝謝,
弗拉德

暫無
暫無

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

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