我在我的Rails项目中使用Elastic Search。我正在使用elasticsearch-model gem进行实时全文搜索。假设模型A属于模型B。如果我在模型A上进行搜索,根据我的搜索参数,我会得到A的10条记录。
A.search(x) => Gives 10 records which includes all attributes of A.但是当我通过A访问模型B时,比如: A.B.some_attrib
undefined method B for <Elasticsearch::Model::Response::Result>如何在ElasticSearch中加载关联?
另外,我希望在搜索结果中的所有记录。如何在搜索方法中指定match_all?
发布于 2016-04-22 19:28:47
有关associated_model,请参阅此链接https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-model/examples/activerecord_associations.rb
Include Elasticsearch::Model and callbacks,并进行索引映射。
包括两个关联模型中模块。
注意:不要忘记导入模型。
发布于 2015-12-04 13:29:05
您可以使用as_indexed_json方法配置模型关联。下面是psuedo代码:
def as_indexed_json(options={})
self.as_json(
include: {
b: { only: :col1}
}
)
endhttps://stackoverflow.com/questions/31875635
复制相似问题