文本字段未针对需要人均字段数据的操作进行优化
从Elasticsearch切换到OpenSearch之后,我的应用程序现在无法运行一个简单的查询:
“文本字段未针对需要的操作进行优化 每个文档字段数据(例如聚合和排序),因此 默认情况下禁用操作。请使用关键字字段 反而。或者,设置fieldData = true [status] 通过解开倒置索引来加载字段数据。请注意,这可以 使用重要的内存。”
有一个问题,涉及相同错误的问题,请 SearchKick / Elasticsearch错误:请改用一个关键字字段。
这是正在运行的查询:
::Record.search(q ? q : "*",
where: where_clause,
fields: fields,
match: :word_middle,
per_page: max_per_page(per_page) || 30,
page: page || 1,
order: sort_clause,
aggs: aggs,
misspellings: {below: 5}
如果我取出aggs,则搜索是可以的,但是它们对于应用程序:status
从聚合字段列表中删除了错误。在数组中,我大概需要为聚合中使用的每个字段指定正确的类型
。 搜索Kick“ rel =“ noreferrer”> https://github.com/ankane/searchkick )
class Product < ApplicationRecord
searchkick mappings: {
properties: {
name: {type: "keyword"}
}
}
end
/ankane /
# in models/Record.rb
mapping_properties = {}
aggregation_fields.each do |af|
mapping_properties[af] = { type: 'keyword' }
end
searchkick mappings: {
properties: mapping_properties
}
com 在链接的帖子中,例如
mappings: {
properties: {
name: {
type: "text",
fielddata: true,
fields: {
keyword: {
type: "keyword"
}
}
}
}
}
...但同样没有运气。
谁能建议如何解决?
Having switched from Elasticsearch to Opensearch, my application now fails to run a simple query with:
"Text fields are not optimised for operations that require
per-document field data like aggregations and sorting, so these
operations are disabled by default. Please use a keyword field
instead. Alternatively, set fielddata=true on [status] in order to
load field data by uninverting the inverted index. Note that this can
use significant memory."
There's a question concerning the same error at Searchkick / Elasticsearch Error: Please use a keyword field instead. Alternatively, set fielddata=true on [name], but there the problem was only affecting tests and I only get the problem (so far) in development mode.
Here's the query being run:
::Record.search(q ? q : "*",
where: where_clause,
fields: fields,
match: :word_middle,
per_page: max_per_page(per_page) || 30,
page: page || 1,
order: sort_clause,
aggs: aggs,
misspellings: {below: 5}
If I take out aggs then the search is fine, but they're essential for the application. Removing :status
from the list of aggregation fields causes the error to name the next field in the array as the problem. So, I presumably need to specify the correct type for each field used in aggregations. But how?
The Searchkick docs suggest this example under "Advanced Mapping" (https://github.com/ankane/searchkick):
class Product < ApplicationRecord
searchkick mappings: {
properties: {
name: {type: "keyword"}
}
}
end
So, I tried this:
# in models/Record.rb
mapping_properties = {}
aggregation_fields.each do |af|
mapping_properties[af] = { type: 'keyword' }
end
searchkick mappings: {
properties: mapping_properties
}
But, the same problem persists. I also tried something similar to that shown in the linked post, e.g.
mappings: {
properties: {
name: {
type: "text",
fielddata: true,
fields: {
keyword: {
type: "keyword"
}
}
}
}
}
...but similarly without luck.
Can anyone suggest how this might be fixed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
即时问题是通过更改用于聚合的所有字段来解决的,而不是:
...在上述搜索查询中。
我用过:
The immediate issue was dealt with by changing all the fields used for aggregations, so rather than:
...in the above search query.
I used:
如果您在删除索引时具有带有弹性搜索的tomcat,它将触发此错误。
停止您的tomcat,再次删除您的索引,然后您就可以了。
希望这对某人有帮助
If you have a Tomcat running with Elastic Search while you delete your index it will trigger this error.
Stop your tomcat, again delete your index and you're good to go.
Hope this helps someone
这与使用OpenSearch无关。取而代之的是,所使用的索引方法导致索引被错误地生成。
请参阅: SearchKick Memory Leak elec
This was not related to using Opensearch. Instead, the method of indexing used caused the indexes to be generated incorrectly.
See: Searchkick memory leak