Hello I have an error about Rails Elasticsearch with searchkick gem
the error
Searchkick::InvalidQueryError ([400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Expected numeric type on field [item_final_price], but got [keyword]"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"items_development_20180507023923980","node":"w7LqCILTTK-gndnoQB1cOQ","reason":{"type":"illegal_argument_exception","reason":"Expected numeric type on field [item_final_price], but got [keyword]"}}]},"status":400}):
Basically telling me the error is expecting numeric type but the type is keywords
heres my search params
in controller.rb
def results
price_ranges = [{to: params[:max_price]}, {from: params[:min_price], to: params[:max_price]}, {from: params[: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
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].to_f, 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].to_f, 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>
and my model
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
Item.import
searchkick callbacks: :async
def search_data
{
item_name: item_name,
item_details: item_details,
item_final_price: item_final_price
}
end
I found my Answer. What I did is change the column datatype from string to float.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.