ElasticSearch范围聚合没有输出结果,没有错误

时间:2018-05-12 17:15:10

标签: ruby-on-rails ruby elasticsearch searchkick

您好我的rails Elascticsearch范围聚合遇到了这个问题,看起来似乎没有错误输出但是它再也没有聚合。

继承我的控制器

def results
    min_price = params[:min_price] if params[:min_price].present?
    max_price = params[:max_price] if params[:max_price].present?

    price_ranges = [{to: max_price}, {from: min_price, to: max_price}, {from: min_price}]
    @results = Item.search(params[:q], aggs: {item_final_price: {ranges: price_ranges}}, page: params[:page], per_page: 10) if params[:q].present?
end

和我的模特

class Item < ApplicationRecord

include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
# Item.import

searchkick callbacks: :async, highlight: [:item_name]



   def search_data
        {
            item_name: item_name,
            item_details: item_details,
            item_final_price: item_final_price,
            item_av_rating: item_av_rating
        }
    end
end

和我的观点

<%= form_tag results_path, method: :get, enforce_utf8: false, id: "q_filter" do %>
<section class="widget widget-categories">
    <%= hidden_field_tag :q, params[:q] %>
    <h3 class="widget-title">Price Range</h3>
    <div class="form-group">
        <label>Price Between</label>
        <%= number_field_tag :min_price, params[:min_price], class: "form-control form-control-sm", placeholder: "Min Price" %>
    </div>
    <div class="form-group">
        <label>And</label>
        <%= number_field_tag :max_price, params[:max_price], class: "form-control form-control-sm", placeholder: "Max Price" %>
    </div>
    <%= button_tag(type: "submit", name: nil, class: "btn btn-outline-primary btn-sm btn-block") do %>
        Filter Search
    <% end %>
</section>
<% @results.each do |item| %>
   <%= item.item_name %>
<% end %>

0 个答案:

没有答案