簡體   English   中英

Tire + Elasticsearch:如何搜索值范圍?

[英]Tire + Elasticsearch: How to search ranges of values?

到目前為止,您一直很喜歡Tyre和elasticsearch,但無法弄清楚如何在以下范圍之間搜索值:

  • age_from age_to
  • 18至20

並返回年齡在這兩個范圍之間的所有配置文件? 我有一個整數列Profile.age

到目前為止功能不完整

def self.search(params)

    #, default_operator: "AND
    tire.search(load: true, page: params[:page], per_page: 20) do
      query do
        should { string params[:query] } if params[:query].present?
        should { integer age_to[:age_to] } if params[:age_to].present?
      end
      to_curl
    end

  end
query do
    should { string params[:query] } if params[:query].present?
    should { range :age, { gte: params[:age_from], lte: params[:age_to] } } if params[:age_to].present? && params[:age_from].present?
end

暫無
暫無

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

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