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.
To search multiple data streams and indices, add them as comma-separated values in the search API's request path. The following request searches the my-index-000001 and my-index-000002 indices. You can also search multiple data streams and indices using an index pattern.
Elasticsearch features a powerful scale-out architecture based on a feature called Sharding. As document volumes grow for a given index, users can add more shards without changing their applications for the most part. Another option available to users is the use of multiple indexes.
Why do you need one per user? What sort of data is it? Elasticsearch does not impose any strict limit to the number of indices or shards, but that does not mean that there are not practical limits. Having an index per user adds a lot of flexibility and isolation, but unfortunately does not scale well at all.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With