Skip to main content

How does Searchkick/ElasticSearch impact how I should structure my database indexes?

Gems / Libraries • Asked by Matias Fernandez

I have a couple of questions about implementing Searchkick and ElasticSearch in general.

  • Let's say I'm using ElasticSearch to search for products like so:

    # usage
    Product.search "apples", fields: [:name]
    -
    # model
    class Product < ApplicationRecord
        searchkick, searchable: [:name], filterable: []
    
        def search_data
            {
                name: name
            }
        end
    end
    

    I don't search by name in any other case (no ActiveRecord queries). Should I remove the table index I have on the name column? (as seen below)

    # remove this?
    add_index :products, :name
    
  • Follow up question: If I'm feeding data to the ElasticSearch server from my database, will indexing (in my db) the search_data fields impact how efficient the Product.reindex function will be? For example:

    # if I have this in my Product model:
    # (It tells ElasticSearch to only reindex the name attribute)
    def search_data
    {
        name: name
    }
    end
    -
    # Does the index by name below impact the reindexing process's speed?
    # If so, is it worth it?
    add_index :products, :name
    
  • Lastly, could Searchkick be the mechanism I use to query most of my data? When is it not recommended to use ElasticSearch? What are some drawbacks, other than losing ActiveRecord functionallity? It seems like it wouldn't be too complicated to add searchkick to mostly all your models and query everything like that.

Thanks in advance for the help! <3


Matias,

Did you ever get an answer to this? I've been wondering about the same things recently.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.