2016-09-19 52 views
0

即使我正在執行相同的搜索,我的elasticsearch目前在不同的環境中會給出不同的結果。 它在我的本地主機的開發工作正常,但它不能在我的測試服務器上工作(不給予預期的記錄,是的,我有數據庫種子)。Elasticsearch在測試服務器上的不同行爲

據我所知,這個應該做的是檢查它是否在三個匹配中找到一個命中,並且它是否返回所有命中。

我正在運行Windows 10,只是使用rails s

服務器運行Ubuntu 16,使用nginx和獨角獸。

這裏是我的映射:(注意:我不能完全肯定的分析是否做任何事情,但它不應該的問題)

settings index: { number_of_shards: 1 } do 
    mappings dynamic: 'true' do 
    indexes :reportdate, type: 'date' 
    indexes :client do 
     indexes :id 
     indexes :name, analyzer: 'dutch' 
    end 
    indexes :animal do 
     indexes :id 
     indexes :species, analyzer: 'dutch' 
     indexes :other_species, analyzer: 'dutch' 
     indexes :chip_code 
    end 
    indexes :locations do 
     indexes :id 
     indexes :street, analyzer: 'dutch' 
     indexes :city, analyzer: 'dutch' 
     indexes :postalcode 
    end 
    end 
end 

這裏是我的搜索:

__elasticsearch__.search({ 
    sort: [ 
    { reportdate: { order: "desc" }}, 
    "_score" 
    ], 
    query: { 
    bool: { 
     should: [ 
     { multi_match: { 
      query: query, 
      type: "phrase_prefix", 
      fields: [ "other_species", "name"] 
     }}, 
     { prefix: { 
      chip_code: query 
     }}, 
     { match_phrase: { 
      "_all": { 
      query: query, 
      fuzziness: "AUTO" 
      } 
     }} 
     ] 
    } 
    } 
}) 

編輯#1 :注意:我對Ruby on Rails相當陌生,大約在2周前開始,在一箇舊項目上進行維護工作,他們還要求提供搜索功能。

+0

您的測試服務器是否繪製了與本地主機相同的數據庫或其他數據庫?此外,分析器還會更改ElasticSearch索引和標記文檔的方式,以確保您在兩臺服務器之間運行相同的設置,或者結果差異很大。 – bkunzi01

+0

他們是不同的數據庫,但它們的種子相同。無論如何,只是發現它可能是軌道緩存文件,並沒有使用更新的文件出於某種原因。無論哪種方式感謝評論,我只是要刪除這個問題,並重新打開另一個,以避免混淆。 (加上它似乎與elasticsearch沒有太大關係) –

+0

Nevermind,一直在用同樣的前提來看待其他答案,它似乎是緩存文件但修正了這個問題,並且這個問題仍然存在。 –

回答

0

原來,問題是我在使用外部表(好吧,有點)和嵌套映射(可能是這個)。

下面是更新後的代碼,在生產和當地工作:

__elasticsearch__.search({ 
    sort: [ 
    { reportdate: { order: "desc" }}, 
    "_score" 
    ], 
    query: { 
    bool: { 
     should: [ 
     { multi_match: { 
      query: query, 
      type: "phrase_prefix", 
      fields: [ "animal.other_species", "client.name"] 
     }}, 
     { prefix: { 
      "animal.chip_code": query 
     }}, 
     { match_phrase: { 
      "_all": { 
      query: query, 
      fuzziness: "AUTO" 
      } 
     }} 
     ] 
    } 
    } 
}) 

不知道爲什麼它不需要動物和客戶端父母preappended雖然它確實需要他們在我的測試服務器上本地工作。然而,這兩種方式都適用。

相關問題