簡體   English   中英

如何在Elasticsearch中將關鍵字更改為數字?

[英]How To Change Keyword to Numeric in Elasticsearch?

您好,我有關於帶有searchkick gem Rails Elasticsearch的錯誤

錯誤

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}):

基本上告訴我錯誤是期望數字類型,但類型是關鍵字

這是我的搜索參數

在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

我的看法

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

和我的模特

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

我找到了答案。 我所做的是將列數據類型從字符串更改為浮點型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM