meilisearch / meilisearch-rails

Meilisearch integration for Ruby on Rails
https://www.meilisearch.com
MIT License
308 stars 47 forks source link

filterableAttributes not set #319

Open jeremylynch opened 9 months ago

jeremylynch commented 9 months ago

We have recently upgraded to meilisearch 1.6.0, and are using meilisearch-rails 0.10.2.

We recently ran into an issue where we had to delete an index and then re-create it. However, after deleting the index, and then manually reindexing the model (Offer.reindex), we had an error for Attribute "manufacturer.name" is not filterable.

As shown below, the filterable_attributes are clearly defined under the model:

filterable_attributes [
    'manufacturer.name'
]

To fix this, I had to manually execute the below:

client.index(‘Offer_production’).update_filterable_attributes([
  ‘manufacturer.name’
])

Why would the filterable_attributes not have been automatically set when calling Manufacturer.reindex!? Is this gem compatible with Meilisearch 1.6 ?

curquiza commented 9 months ago

Hello @jeremylynch Thanks for the report!

@ellnix if you are around, I would love to have your help on this 😊 Do you know where it could come from? Thank you very much for your help

ellnix commented 9 months ago

There are models with filterable_attributes set in the test suite and they seem to be behaving normally. There have been some changes to the settings logic but they are not included in v0.10.2.

... reindexing the model (Manufacturer.reindex), ...

As shown below, the filterable_attributes are clearly defined under the model:

filterable_attributes [
    'manufacturer.name'
]

This does not look like it was defined in the Manufacturer model, but rather an Offer model of some kind (judging by the index name). If I am correct, then this block would have been run on Offer.reindex!, not Manufacturer.reindex!.

If that is not the case let me ask some follow up questions:

  1. Did the error appear when you attempted to search or during the reindex?
  2. Is the Offer_production index set on the Manufacturer model?
  3. Is deleting and rebuilding Manufacturer indexes the only change in your use that could relate to this error? Were other indexes rebuilt?
jeremylynch commented 9 months ago

Apologies, in my original issue I had Manufacturer.reindex! this should have been Offer.reindex! which created the confusion in your question (I have since edited the original question).

The issue was cause by simply deleting the index, and then attempting to reindex all the records (with Offer.reindex!)

NielXu commented 2 weeks ago

I encountered the same issue:

  1. First delete an existing index
  2. Then reindex! it and the settings are gone

Meilisearch definition:

  meilisearch enqueue: :sync_article_to_meilisearch do
    searchable_attributes [:title, :description]
    filterable_attributes [:id, :type]
    attribute :type
    attribute :title
    attribute :created_at
    attribute :description
    attribute :published
  end

  def self.sync_article_to_meilisearch(article, remove)
    if published && !remove
      article.index!
    else
      Article.index.delete_document(article.id)
    end
  end

Then I call

Article.index.delete # Make sure the index does not exist
Article.reindex!

The settings

irb(main):004:0> Article.index.settings
=> 
{"displayedAttributes"=>["*"],                                                                            
 "searchableAttributes"=>["*"],                                                                           
 "filterableAttributes"=>[],                                                                              
 "sortableAttributes"=>[],                                                                                
 "rankingRules"=>["words", "typo", "proximity", "attribute", "sort", "exactness"],                        
 "stopWords"=>[],                                                                                         
 "synonyms"=>{},                                                                                          
 "distinctAttribute"=>nil,                                                                                
 "typoTolerance"=>{"enabled"=>true, "minWordSizeForTypos"=>{"oneTypo"=>5, "twoTypos"=>9}, "disableOnWords"=>[], "disableOnAttributes"=>[]},
 "faceting"=>{"maxValuesPerFacet"=>100},                                                                  
 "pagination"=>{"maxTotalHits"=>1000}}