【发布时间】:2018-08-22 04:29:37
【问题描述】:
所以我在 Rails 中的模型的 ElasticSearch 关注点中有以下模块。
这是可行的,但是如何让每个 bool 查询(must、must_not、filter)接受 nil 或空参数?
如果我传递一个空的query_string,它将获取所有文件。
然后当我传递一个空的size 参数时,它将返回所有尺寸。
module ClassMethods
def home_page_search(query_string, size, start_date, end_date)
search({
query: {
bool: {
must: [
{
multi_match: {
query: query_string,
fields: [:brand, :name, :notes, :size_notes]
}
}
],
must_not: [
range: {
unavailable_dates: { gte: start_date, lte: end_date }
}
],
filter: [
{ term: { size: size } }
]
}
}
})
end
end
【问题讨论】:
标签: ruby-on-rails elasticsearch