簡體   English   中英

使用Searchkick在ElasticSearch中搜索子文檔

[英]Search subdocuments in ElasticSearch with Searchkick

假設我要搜索一系列嵌入式文檔或子文檔,但是將它們的父母作為我的結果返回,例如“建築物和單元”:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM