1

Right now my Rails application allows users to search only the database fields. They can upload a picture and then search with the name. I am also extracting the metadata and storing it in YAML files. So for fileA, the metadata is stored in fileA.yml file.

With Elasticsearch, I was able to index the table 'file' and allow users to search according to filetype, filename, etc. (whatever's stored on the DB). However, I'd like to provide a metadata search also, so how do I index that file's YAML file also?

I'm okay with switching to some other search provider, like Solr, if it's needed also.

1 Answer 1

3

You don't mention what library (elasticsearch-rails, searchkick etc.) you are using to integrate with elasticsearch but they all allow you to customise the data that is sent for indexing.

For example with elasticsearch-rails you override the as_indexed_json method, for example

def as_indexed_json(options={})
  as_json(options).merge(data_from_yaml)
end

for searchkick, you would do

def search_data
  as_json.merge(data_from_yaml)
end
Sign up to request clarification or add additional context in comments.

3 Comments

I am using the search kick gem to integrate elastic search. Can I do the customizations with this gem or do I need to use the elastic search-model gem?
Not sure if elasticserach-model is a gem, but this is what I meant: github.com/elasticsearch/elasticsearch-rails/tree/master/…
@SwaathiK yes you can do this with searchkick - the method just has to have a different name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.