排序失败 "reason":"Fielddata is disabled on text fields by default.?

在尝试3. 排序时失败,给出这样的提示:

$results = app('es')->search($params);

Elasticsearch/Common/Exceptions/BadRequest400Exception with message '{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [price] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"products","node":"zWcApYbZSwGrLNQlVU_lWg","reason":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [price] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."}}],"caused_by":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [price] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.","caused_by":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [price] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."}}},"status":400}'

请问有人知道是因为什么吗?

谢谢

file

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
leo
最佳答案

@邱贤 是不是 price 字段格式不对?应该是 float,看这个报错应该是被你设置成了 text 类型。

5年前 评论
讨论数量: 12
leo

把你的 $params 贴出来

5年前 评论

@leo

[
"index" => "products",
"type" => "_doc",
"body" => [
"from" => 0,
"size" => 5,
"query" => [
"bool" => [
"filter" => [
[
"term" => [
"on_sale" => true,
],
],
],
],
],
"sort" => [
[
"price" => "desc",
],
],
],
]

就是 直接复制的呢

5年前 评论
leo

@邱贤 是不是 price 字段格式不对?应该是 float,看这个报错应该是被你设置成了 text 类型。

5年前 评论

@leo

我应该没改过呀😭

我自己在研究一下好了,还是谢谢!

file

5年前 评论
leo

@邱贤 我说的是在 Elasticsearch 里的字段类型

5年前 评论

@leo 这个 Elasticsearch 里的字段类型 在哪里设置的? 我也遇到了同样的问题

5年前 评论
leo

@mmz 请从 6.5 节开始重新学习

5年前 评论

@leo OK 解决了。 感谢

5年前 评论

@mmz 请问你是怎么解决的啊?

5年前 评论

@windtalker 就上面最佳答案。类型的问题

5年前 评论

晕啊, 就上面最佳答案。类型的问题。 这是什么答案呀, laravel 中怎么设置 类型??

4年前 评论

@gg22mm 跟laravel没关系 是你es mapping的问题 创建索引的时候类型错了 "price": { "type": "scaled_float", "scaling_factor": 100 },

file

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!