这可能很简单,但我做不出来。我在Project类上有这个轮胎/elasicsearch查询:
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我需要状态项在“posted”或“closed”上进行搜索,但无法解决此问题。我尝试了term :status,"posted","closed“,但没有返回结果,所以可能是在做AND操作。感谢这里正确的轮胎语法。(注意这里不寻找jason/elasticsearch字符串)非常感谢!
发布于 2012-07-25 18:00:07
您需要的是一个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。
https://stackoverflow.com/questions/11615093
复制相似问题