Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add the ability to define how models are mapped to hits. #428

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

Closed

Conversation

@AaronRustad
Copy link
Contributor

@AaronRustad AaronRustad commented Jun 15, 2015

This PR addresses #421

When searching against aliases, results from Elasticsearch are returned with the actual _index name rather than the alias name. The current implementation of Multiple Model Search uses the _index to determine which model to use. Unfortunately, when working with an aliased index, this mapping fails.

I don't think there is a 'correct' way to get around this, other than to give the user of the library the option of setting the logic for determining how to map indices to aliased models.

This PR gives the option of overriding the default model to hit selection code.

For example, in production, I'll use a timestamped index like `content-20150515164511'.

# INITIALIZER
Elasticsearch::Model.model_to_hit_selector = lambda do |model,hit|
 /#{model.index_name}-.*/ =~ hit[:_index] && model.document_type == hit[:_type]
end

gareth reacted with thumbs up emoji 9toon reacted with heart emoji
Copy link
Contributor Author

Is there any interest in seeing this merged... I know I am! ;-)

Copy link

I am facing the exact same problem ... can we merge this solution?

Copy link
Contributor

karmi commented May 31, 2016

Hi, ugh, this is one of the PRs which has slipped by... I was concentrated on other things for a long strecth of time, and in the last weeks was more focused on the Ruby client (preparing for the 5.0 release and similar).

I like the idea of a lambda, @AaronRustad, you know I do :) I'll look into this today or tomorrow, please bug me until we sort this out. Sorry to put the strain on you, but it would help me...

Copy link

gareth commented Jul 1, 2016

This error has just bitten us too, I'm definitely interested in getting a solution merged

Copy link
Contributor Author

Lol, I haven't bugged you for a while @karmi .... I've since moved on and I'm not sure there is any interest in this any more. Shall we close it?

Copy link
Contributor

ryansch commented Mar 8, 2018
edited
Loading

We just hit our heads on this while shipping a bunch of stuff into production.

@karmi The default behaviour should allow the index name followed by anything to match.

Elasticsearch::Model.model_to_hit_selector = lambda do |model, hit|
 /#{model.index_name}.*/ =~ hit[:_index] && model.document_type == hit[:_type]
end
morganick reacted with thumbs up emoji

leiz-me added a commit to leiz-me/elasticsearch-rails that referenced this pull request Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /