-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multi-index search #38
Comments
Multi-index search would be nice. What are your thoughts on the best way to declare indexes? |
(fixed the example above, was missing 'index.name' calls) what about something this:
|
Is this method still pending to search across multiple models. I want to use boost and autocomplete across multiple models. If searching on a particular model using index names like:
then, boost will be applied only for that Model1. How can i use boost across multiple models. Like in tire, we can define it while indexing in mapping. |
Quick (perhaps silly) question, how can I get the index name for a model? |
It's now |
Holy moly that was a fast response. Much appreciated. |
Haha, no problem - right place, right time. |
Ok second question; how can I get the current full index name? Test.searchkick_index.name is returning "test_development" But my actual index_name is "test_development_20140219162300398" etc. I need the full name in order to use it alongside index_name: when searching across multiple models. |
You should use the alias when searching across models - it's more robust and gives you the same results. |
Ah my bad, I had mistyped an index name. Thanks again. |
+1 to multi-index search. @liberatiluca's suggestion would be awesome. |
The workaroud which is on the very top of the page doesn't work because |
I used this for an autocomplete field to match multiple models (indexes) : results = []
[Model1, Model2, Model3, Model4].each do |model|
query = Searchkick::Query.new model, params[:query], load: false, fields: [{name: :text_start}], limit: 10
results = results.concat query.execute.response['hits']['hits']
end
results.sort_by! { |r| r['_score'] }.reverse!
render json: {
all: results.map { |r| { value: r['_source']['name'] } }.first(10)
} It shouldn't be too much of a hastle to add a method that uses this logic to the |
@amenzhinsky Oops, just fixed. Need to add a test for that. cec8c58 @jdurand What's the advantage to this approach vs the |
@ankane I never got the index_name approach to work and, if I understood correctly, this approach would not let you define different search criterion (ie: boost) for each model.
I'm just tossing ideas around... |
Has this been implemented into searchkick yet? |
Another solution for the multimodel search (this will search across all searchkick indexes) |
Is it possible to specify an includes option for each model type doing a multisearch that way? |
Hi,
I tried using it like this but all the results comes only from Model1. Is there anyway to get results from both models. Both models have different attributes. |
👍 |
The solution I have found comes from using the # app/models/foo.rb
class Foo
searchkick
def search_data
{ name: name }
end
def name
end
end
# app/models/bar.rb
class Bar
searchkick
def search_data
{ name: name }
end
def name
end
end
results = Searchkick.search('query') This will search every index with the If you want to search just specific fields # update the `search_data` method to contain your other field
# app/models/foo.rb
class Foo
searchkick
def search_data
{ name: name,
description: description }
end
def name
end
def description
end
end
# you can then define which fields to search
results = Searchkick.search('query', fields: ['name', 'description'])
# Cool part is, if one model/index has a field the others don't, searchkick will still work as expected
results = Searchkick.search('query', fields: ['name', 'description', 'unique_field'])
# if you want to boost a certain field, put a carrot to power
results = Searchkick.search('query', fields: ['name^10', 'description']) |
This feature was added to the documentation in July: bd12de7 I'm unsure when the code was implemented. Does anyone know if it's possible to search multiple indices (ie |
@MrHubble You'll need use multi search instead (basically, two separate queries) if you want different |
Closing this issue as multi-index search is now supported. Please create a new issue if I missed anything or there are future questions. |
@ankane Sorry to bother, but how can I sort results by _score in a multi_search example?
I'd like to see organizations with higher score before than users. Thanks in advance |
You'll need to do this in Ruby. Also, as mentioned in the comment above, please create a new issue for new questions so the 15 other subscribers to this issue aren't spammed. |
Searchkick should support multi-index search.
I have overcome this by using:
it works ok, but it's just wrong to have to do this.
Maybe the starting point can be #36?
The text was updated successfully, but these errors were encountered: