简体   繁体   中英

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) 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM