2012-07-23 48 views
1

這可能很簡單,但我不能解決它。我對工程類這款輪胎/ elasicsearch查詢:或查詢與輪胎/ Elastic

def self.search(params) 
    tire.search(load: true, page: params[:page], per_page: 8) do 
     query do 
     boolean do 
      must { string params[:query], default_operator: "AND" } if params[:query].present? 
      must { term :status, "posted" } 
      must { term :budget, params[:budget] } if params[:budget].present? 
     end 
     end 
    end 
    end 

我需要的狀態長期是在「貼」或「關閉」,不能工作了這一點搜索。我嘗試了術語:status,[「posted」,「closed」],但是這不會返回結果,因此可能會執行AND。 請在此感謝正確的輪胎語法。 (NB在這裏找不到jason/elasticsearch字符串) 非常感謝!

回答

5

你需要的是一個terms查詢,這確實是一個數組傳遞術語之間的OR

must { terms :status, ["posted"] } 

或像這樣的動態值:

# params[:status] can be single value or array 
must { terms :status, Array(params[:status]) } 

更多信息,請參見this part of Tire documentation和上下文。

+0

謝謝,沒有發現術語與術語之間的區別是文檔 – bobomoreno 2012-07-25 10:12:59