有人对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
文章\u 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\u cause”:[{“type”:“非法\u参数\u exception”,“reason”:“未找到字段[status.suggest]”的Map,}],“type”:“search\u phase\u execution \u exception”,“reason”:“all shards failed”,“phase”:“query”,“grouped”:true,“failed\u shards”:[{“shard”:0,“index”:“articles\u development\u 202009181949310”,“node”:“hvbrsnsiqgw6xsm7pg-36a”,“reason”:{“type”:“非法参数\u异常”,“reason”:“未找到字段[status.suggest]”的Map”,“caused \u by”:{“type”:“非法参数\u异常”,“reason”:“未找到字段[status.suggest]”,“caused \u by”:{“type”:“非法参数\u异常”,“reason”:“未找到字段[status.suggest]”的Map,“状态”:400}):
1条答案
按热度按时间k5ifujac1#
翻译为
你注意到了吗
:"author.name"
? 在您的数据库中肯定不会有这样的列。如果你想搜索
author
的名字article
有一个author
,您需要将其索引为author_name
在你的search_data
中的方法Article
然后你就可以用