首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >elasticsearch-rails空结果

elasticsearch-rails空结果
EN

Stack Overflow用户
提问于 2014-09-17 07:29:06
回答 1查看 1.2K关注 0票数 5

我已经执行了Comment.import,它返回0,这意味着在导入过程中没有错误。

我已经做过Comment.__elasticsearch__.refresh_index!

这是我正在使用的模型:

代码语言:javascript
复制
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

但是,我对elasticsearch的所有查询都会返回一个空数组作为命中。

代码语言:javascript
复制
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" : [ ]
  }
}

我的数据库中有数据,但我不知道为什么它从来不会被过滤。你知道为什么会发生这种情况吗?这快把我逼疯了

不管我怎么做,点击总是空的

EN

回答 1

Stack Overflow用户

发布于 2015-08-18 21:45:25

您可以尝试将type:string添加到indexes :descriptionindexes :author中吗

我还记得我在使用as_json时遇到了问题,对于较老的rails版本,它将包含根属性。尝试将其设置为false,您可以全局或在as_json( root: false )中执行此操作

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25879959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档