Save 36% for Black Friday! Learn more

Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Matias Fernandez asked in Gems / Libraries

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

Reply

Matias,

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

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,110+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.