VoodooChild92
VoodooChild92

Reputation: 2053

ElasticSearch : Index the results of a method that has arguments

I'm working on a Rails application which is supposed to be scalable to at least 100k users. But, when we populated enough data in our DB, it significantly slows down and we planned to use ElasticSearch as a cure. My question mainly concerns with the users listing page that I've in my site where a particular function is CPU-intensive and we wish to index that function.

So, here is the catch. This function has arguments that we're not able to avoid and I've not found any example that can suggest me how I can pass arguments to the indexed functions.

Here's a question that I found helpful : Index the results of a method in ElasticSearch (Tire + ActiveRecord)

Upvotes: 0

Views: 75

Answers (1)

Igor Guzak
Igor Guzak

Reputation: 2165

you could try write something like:

def to_indexed_json
  { field: method(args) }.to_json
end

or even without to_indexed_json you could write:

mapping do
  indexes :field_name
end

def field_name
  your_method(args)
end

Upvotes: 1

Related Questions