简体   繁体   English

ElasticSearch Range Aggregation没有输出结果,没有错误

[英]ElasticSearch Range Aggregation no output results with no error

Hello I've got this problem with the rails Elascticsearch range aggregations, it seems right as there's no error output but then again it also doesn't aggregate. 您好,我在Rails Elascticsearch范围聚合中遇到了这个问题,这似乎是正确的,因为没有错误输出,但同样也没有聚合。

Heres my controller 继承人我的控制器

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

and my model 和我的模特

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

and my views 和我的看法

<%= 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 %>

Try to target this in your view 尝试针对您的目标

@results.response["aggregations"]["item_final_price"]["buckets"]

If you're running in development, can you throw a binding.pry and see what the result keys are? 如果您正在开发中,是否可以抛出binding.pry并查看结果键是什么? The data should be there if the query returns results. 如果查询返回结果,则数据应该在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM