Reputation: 22183
Large web applications offer a "global" search which combines data from various fulltext indices (this would be a table in SQL) to provide a combined search result ordered by its score. So lets say you have videos, blog articles and users, then when you type in "home" into the search it could yield results like this (ordered by score):
Does anyone know how to perform such a combined search using ElasticSearch? Preferably using the Tire gem for Rails, but raw ElasticSearch JSON data would also work.
Thanks.
Upvotes: 12
Views: 5992
Reputation: 14419
regarding Tire, there's an important distinction: are you using it standalone or in the ActiveRecord/ActiveModel integration.
In the former case, just search against multiple indices, Tire.search ['indexA', 'indexB'] do ... end
. Or search against the whole cluster, Tire.search do ... end
(equivalent to curl 'http://localhost:9200/_search?q=*'
).
In the latter case, Tire does not handle multi-model searches well, at the moment. Notice this pull request: https://github.com/karmi/tire/pull/218 -- build your gem with this patch applied and help test out the solution.
UPDATE
Current Tire (> 0.4) can load multiple model instances just fine. See the integration test for example.
Upvotes: 16
Reputation: 4477
I'm pretty sure that the http://127.0.0.1:9200/_search endpoint will do the trick for you. Over 99% of my data is in one index, so its hard for me to verify this for you here.
Also, check out the multi-search endpoint: http://www.elasticsearch.org/guide/reference/api/multi-search.html
Upvotes: 1