使用Searchkick在ElasticSearch中搜索子文档

假设我有一系列我想要搜索的嵌入式或子级文档,但返回他们的父母作为我的结果,如建筑物和单位:

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}}