kni*_*irr 19 opensearch elasticsearch searchkick
从 Elasticsearch 切换到 Opensearch 后,我的应用程序现在无法使用以下命令运行简单查询:
“文本字段没有针对需要每个文档字段数据的操作(例如聚合和排序)进行优化,因此默认情况下禁用这些操作。请改用关键字字段。或者,在 [status] 上设置 fielddata=true 以便加载字段通过反转倒排索引来恢复数据。请注意,这可能会使用大量内存。”
在Searchkick / Elasticsearch Error: Please use a keywords field 相反,有一个关于相同错误的问题。或者,在 [name] 上设置 fielddata=true,但问题仅影响测试,并且我仅在开发模式下遇到问题(到目前为止)。
这是正在运行的查询:
::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}
Run Code Online (Sandbox Code Playgroud)
如果我取出 aggs,那么搜索就可以了,但它们对于应用程序来说是必不可少的。:status
从聚合字段列表中删除会导致错误将数组中的下一个字段命名为问题。因此,我可能需要为聚合中使用的每个字段指定正确的类型。但如何呢?
Searchkick 文档在“高级映射”( https://github.com/ankane/searchkick ) 下建议使用此示例:
class Product < ApplicationRecord
searchkick mappings: {
properties: {
name: {type: "keyword"}
}
}
end
Run Code Online (Sandbox Code Playgroud)
所以,我尝试了这个:
# in models/Record.rb
mapping_properties = {}
aggregation_fields.each do |af|
mapping_properties[af] = { type: 'keyword' }
end
searchkick mappings: {
properties: mapping_properties
}
Run Code Online (Sandbox Code Playgroud)
但是,同样的问题仍然存在。我还尝试了类似于链接帖子中显示的内容,例如
mappings: {
properties: {
name: {
type: "text",
fielddata: true,
fields: {
keyword: {
type: "keyword"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
...但同样没有运气。
谁能建议如何解决这个问题?
kni*_*irr 18
通过更改用于聚合的所有字段来解决眼前的问题,而不是:
aggs = %w(field1 field2 field3 ...)
Run Code Online (Sandbox Code Playgroud)
...在上面的搜索查询中。我用了:
aggs = %w(field1.keyword field2.keyword field3.keyword ...)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
40628 次 |
最近记录: |