这里是完整的错误消息:
Searchkick :: InvalidQueryError:Searchkick :: InvalidQueryError: [400] {"错误" {" ROOT_CAUSE":[{"类型":" illegal_argument_exception""理由":& #34; Fielddata 默认情况下在文本字段上禁用。设置fielddata = true [foo_name]为了通过uninverting在内存中加载fielddata 倒排索引。请注意,这可能很重要 。存储器"}],"类型":" search_phase_execution_exception""理由":"所有 碎片 失败""相":"查询""分组":真," failed_shards":[{"碎片& #34;:0,"指数":" foos_test""节点":" k0yYkVnIQzaXbvpAG_rKgw""理由" :{"类型":" illegal_argument_exception""理由":" Fielddata 默认情况下在文本字段上禁用。设置fielddata = true [foo_name]为了通过uninverting在内存中加载fielddata 倒排索引。请注意,这可能很重要 。存储器"}}]," caused_by" {"类型":" illegal_argument_exception""理由":&#34 ; Fielddata 默认情况下在文本字段上禁用。设置fielddata = true [foo_name]为了通过uninverting在内存中加载fielddata 倒排索引。请注意,这可能很重要 。存储器"}},"状态" 400}
当我在索引操作中添加以下代码时,我收到此错误(此错误仅显示在minitest中):
order: {foo_name: :asc}
这是我的完整索引代码:
def index
query = params[:q].presence || "*"
@foos = Foo.search(
query,
page: params[:page], per_page: 25,
order: {foo_name: :asc}
)
end
end
我使用的是Searchkick。
答案 0 :(得分:2)
这是一个讨厌的人;我们很幸运能够找到解决方案。我假设你的模型看起来像这样:
class Foo
attr_accessor :foo_name
searchkick # some settings
def search_data
{ foo_name: foo_name }
end
end
您需要做的是定义一个foo_name_sort字段,其值与foo_name相同,但设置为filterable:
class Foo
attr_accessor :foo_name
searchkick # some settings,
filterable [:foo_name_sort]
def search_data
{ foo_name: foo_name,
foo_name_sort: foo_name }
end
end
然后搜索:
@foos = Foo.search(
query,
page: params[:page], per_page: 25,
order: {foo_name_sort: :asc}
)
答案 1 :(得分:0)
试试这个
def index
query = params[:q].presence || "*"
@foos = Foo.search(
query,
page: params[:page], per_page: 25,
aggs: {foo_name: {order: {"_term" => "asc"}}}
)
end
答案 2 :(得分:0)
这样写您的订单:
order: {'foo_name.keyword' => 'asc'}