假设我要搜索一系列嵌入式文档或子文档,但是将它们的 parent 作为我的结果返回,例如“建筑物和单元”:
Building A
- Unit 1F
- Unit 1R
- Unit 2F: 1200 sq ft
- Unit 2R: 2300 sq ft
Building B
- Unit 202: 500 sq ft
- Unit 203: 650 sq ft
现在假设我要退回所有单位> = 1000平方英尺的建筑物。我该怎么做?
最佳答案
将单位大小存储为数组:
class Building
def search_data
{
# ... other fields
unit_sq_ft: units.map(&:sq_ft)
}
end
end
并搜索:
Building.search "pool", where: {unit_sq_ft: {gte: 1000}}
关于ruby-on-rails - 使用Searchkick在ElasticSearch中搜索子文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23544048/