Skip to content

Conversation

@AaronRustad
Copy link
Contributor

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

@AaronRustad
Copy link
Contributor Author

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

@hongsheng-razoo
Copy link

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

@karmi
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...

@karmi karmi added the feature label May 31, 2016
@gareth
Copy link

gareth commented Jul 1, 2016

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

@AaronRustad
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?

@ryansch
Copy link
Contributor

ryansch commented Mar 8, 2018

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

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants