Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch/Tire only returning results for one index

Right now I have the following code:

search = Tire.search ['object1_index', 'object2_index'] do |search|
  search.query { string params[:q] }
end

@results = search.results

The results right now are all coming from just object1, however, if I remove 'object1_index' with the same query, I do get object2 results. How can I get my search to interact with both indices at once?

edit:

I now have the following (using the search I have defined on my models), but as I will be eventually adding pagination I'm unsure if this is the best work around:

object1_results = Object1.search(params).results
object2_results = Object2.search(params).results
@results = object1_results + object2_results
@results.sort!(&:_score) 
like image 772
Lindsey B Avatar asked Nov 02 '22 11:11

Lindsey B


1 Answers

Just add size parameter since elasticsearch default size is 10 which must be only limiting to object1_index search space in your case

search = Tire.search ['object1_index', 'object2_index'], size: 1000 do |search|
...

Update

For pagination, you can add from parameter

like image 181
maximus ツ Avatar answered Nov 13 '22 19:11

maximus ツ