2016-09-19 42 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虽然它确实需要他们在我的测试服务器上本地工作。然而,这两种方式都适用。

相关问题