简体   繁体   English

elasticsearch-rails空结果

[英]elasticsearch-rails empty results

I already did Comment.import and it returned 0, which means there were no errors during the import process. 我已经做了Comment.import并返回0,这意味着在导入过程中没有错误。

I already did Comment.__elasticsearch__.refresh_index! 我已经做过Comment.__elasticsearch__.refresh_index!

This is the model I'm using: 这是我正在使用的模型:

require "datamapper_adapter"

class Comment
  include DataMapper::Resource

  include Elasticsearch::Model

  property :id, Serial
  property :email, String
  property :author, String
  property :description, String
  property :created_at, DateTime

  belongs_to :picture

  validates_presence_of :email, :author, :description

  settings index: { number_of_shards: 1 } do
    mappings dynamic: 'false' do
      indexes :id, analyzer: 'english', index_options: 'offsets'
      indexes :author, analyzer: 'english', index_options: 'offsets'
      indexes :description, analyzer: 'english', index_options: 'offsets'
    end
  end

  def as_indexed_json(options={})
    as_json.except("picture_id", "created_at", "email", "_persistence_state", "_repository", "_id")
  end
end

And still all my queries to the elasticsearch return an empty array as hits. 而且我对elasticsearch的所有查询都返回一个空数组作为命中。

curl -XPOST 'http://localhost:9200/comments/comment/_search?pretty
{
    "took" : 35,
    "timed_out" : false,
    "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
    "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

I have data in my DB but I have no idea why it never gets filtered. 我的数据库中有数据,但我不知道它为什么永远不会被过滤掉。 Any ideas why this is happening? 任何想法为什么会这样? This is driving me nuts 这让我疯了

No matter what I do, hits is ALWAYS empty 无论我做什么,点击总是空的

could you try to add type:string to indexes :description and indexes :author 你可以尝试添加type:stringindexes :descriptionindexes :author

I also remember I had problem with as_json, for older rails versions it will include root attribute. 我还记得我有as_json的问题,对于旧的rails版本,它将包含root属性。 Try to set it to false, you can do this globally or in the as_json( root: false ) 尝试将其设置为false,您可以全局或在as_json( root: false )执行此as_json( root: false )

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

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