简体   繁体   English

Elasticsearch在测试服务器上的不同行为

[英]Elasticsearch different behaviour on test server

My elasticsearch is currently giving different results on different environments even though I'm doing the same search. 尽管我进行相同的搜索,但我的Elasticsearch当前在不同的环境下给出不同的结果。 It works fine in development on my localhost, however it doesn't work on my test server (doesn't give expected records, yes I do have the database seeded). 它在我的本地主机上的开发中运行良好,但是在我的测试服务器上不起作用(不提供预期的记录,是的,我确实拥有数据库种子)。

Far as I understand what this should do is check whether it finds a hit on one of the three matches, and if it does return all the hits. 据我了解,这应该做的是检查它是否在三个匹配项之一中找到匹配项,并且是否确实返回了所有匹配项。

I'm running Windows 10, just using rails s . 我正在运行Windows 10,仅使用rails s

The server is running Ubuntu 16, using nginx and unicorn. 该服务器正在使用nginx和unicorn运行Ubuntu 16。

Here's my mapping: (note: I'm not completely sure whether the analyzer does anything but it shouldn't matter) 这是我的映射:(请注意:我不完全确定分析器是否执行任何操作,但这无关紧要)

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

Here's my search: 这是我的搜索:

__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"
          }
        }}
      ]
    }
  }
})

EDIT #1: Note: I'm fairly new to ruby on rails, started about 2 weeks ago, doing maintenance work on an old project and they also requested a search function. 编辑#1:注意:我对Rails还是比较陌生的,大约2周前开始,对一个旧项目进行维护工作,他们还要求搜索功能。

Turns out that the problem was that I was using foreign tables (well, kinda) and nested mapping (probably this). 事实证明,问题在于我正在使用外部表(好吧)和嵌套映射(可能是这样)。

Here's the updated code that works on both production and locally: 这是可在生产环境和本地环境使用的更新代码:

__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"
          }
        }}
      ]
    }
  }
})

Not sure why it doesn't need the animal and client parents preappended to work locally whilst it does need them on my testing server. 不知道为什么不需要动物和父母的父母在本地工作,而在我的测试服务器上确实需要它们。 However this works on both this way. 但是,这两种方式都有效。

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

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