gpt4 book ai didi

ruby-on-rails - Rails 4 elasticsearch使用多个搜索条件,结合了搜索功能

转载 作者:行者123 更新时间:2023-12-02 23:27:38 25 4
gpt4 key购买 nike

我正在为项目使用elasticsearch-rails,有一个组合搜索功能,所有列都在一个表中。我只是编写了一个自定义搜索功能,但搜索dsl无效,无法获得任何结果。

def self.combine_search_filter(remark=nil, sim_card_supplier_id=nil, work_mode=nil, operator_status=nil, platform_management_status=nil, online_status=nil, sim_card_set_id=nil, iccid_from=nil, iccid_to=nil, actived_at_from=nil, actived_at_to=nil, check_in_at_from=nil, check_in_at_to=nil, device_mac_from=nil, device_mac_to=nil)
response = __elasticsearch__.search(
"size": 1000,
"query": {
"filtered": {
"filter": {
"bool": {
"filter": [
{ "term": { "sim_card_supplier_id": sim_card_supplier_id } },
{ "term": { "work_mode": work_mode } },
{ "term": { "operator_status": operator_status } },
{ "term": { "platform_management_status": platform_management_status } },
{ "term": { "online_status": online_status } },
{ "term": { "sim_card_set_id": sim_card_supplier_id } }
{ "range": { "iccid": { "from": iccid_from, "to": iccid_to }}},
{ "range": { "check_in_at": { "from": check_in_at_from, "to": check_in_at_to }}},
{ "range": { "actived_at": { "from": actived_at_from, "to": actived_at_to }}},
{ "range": { "device_mac": { "from": device_mac_from, "to": device_mac_to }}}
]
}
}
}
}
)
end

并且参数可能会通过nil,我该怎么做才能使搜索DSL有效?

最佳答案

我宁愿建议您将searchkick gem用于rails,这样可以使 flex 搜索如此简单,并使搜索更智能,查询也更简单。

关于ruby-on-rails - Rails 4 elasticsearch使用多个搜索条件,结合了搜索功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41031187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com