-1

Someone is having this kind of problem with searchkick? I did something wrong?

article.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":"no mapping found for field [status.suggest]"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"articles_development_20200918194930310","node":"hVbRSnSiQGW6xSM7pG-36A","reason":{"type":"illegal_argument_exception","reason":"no mapping found for field [status.suggest]"}}],"caused_by":{"type":"illegal_argument_exception","reason":"no mapping found for field [status.suggest]","caused_by":{"type":"illegal_argument_exception","reason":"no mapping found for field [status.suggest]"}}},"status":400}):

1 Answers1

1
fields: %i[title body author.name status]

translated to

fields: [:title, :body, :"author.name", :status]

did you noticed :"author.name"? there will not be such column for sure in your DB.

If you are looking to search by author's name assuming an article has one author, you need to index it as a filed like author_name in your search_data method in the Article model and then you will be able to search it using

fields: %i[title body author_name status]
Amit Patel
  • 15,609
  • 18
  • 68
  • 106
  • thanx for your response, my problem is with suggessionts and not with author_name –  Sep 19 '20 at 11:02