[英]Searchkick::InvalidQueryError 400 error running elasticsearch/searchkick in cloud9?
[英]searchkick 400 Searchkick::InvalidQueryError for suggestions
有人在使用 searchkick 时遇到这种问题吗? 我做错事情了?
文章.rb
searchkick suggest: [:status]
scope :search_import, -> { includes(:author, :medium, :tags) }
has_many :article_tags
has_many :tags, through: :article_tags
belongs_to :author
belongs_to :medium
article_controller.rb
def search_article
result_articles = Article.search params[:search],
suggest: true,
fields: %i[title body author.name status],
page: params[:page],
per_page: params[:per_page]
render json: { result_articles: result_articles , time: result_articles.took, suggestion:
result_articles.suggestions }
end
Searchkick::InvalidQueryError ([400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"未找到字段 [status.suggest]"}],"type" :"search_phase_execution_exception","reason":"所有分片失败","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"articles_development_20200918194930310"," node":"hVbRSnSiQGW6xSM7pG-36A","reason":{"type":"illegal_argument_exception","reason":"未找到字段 [status.suggest]"}}],"caused_by":{"type" :"illegal_argument_exception","reason":"未找到字段 [status.suggest] 的映射","caused_by":{"type":"illegal_argument_exception","reason":"未找到字段 [status.suggest] 的映射"}}},"status":400}):
fields: %i[title body author.name status]
翻译成
fields: [:title, :body, :"author.name", :status]
你注意到:"author.name"
吗? 您的数据库中肯定不会有这样的列。
如果您想在假设article
只有一个author
按author
姓名进行搜索,则需要在Article
模型的search_data
方法中将其索引为类似author_name
,然后您就可以使用
fields: %i[title body author_name status]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.