Wednesday, 7 August 2013

Random sort with Tire and ElasticSearch

Random sort with Tire and ElasticSearch

I'm having difficulty sorting the results of my search randomly.
def self.search(params)
tire.search do
query { string params }
sort { _script: { script: "(doc['id'].stringValue + salt).hashCode()",
type: "number",
params: { salt: "some_salt" }
order: "asc" } }
end
end
I'm essentially following this post.
The error I'm receiving is syntax error, unexpected ':', expecting '}'
around the line beginning with "sort". I'm guessing Tire isn't
syntactically mapped 1:1 with the sort portion of ElasticSearch's Query
DSL.
Any thoughts on what I can do? I'm considering an alternative method
brought up in the aforementioned linked post where I create a randomized
field in the model and sort against that.

No comments:

Post a Comment