Skip to content
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

Unexpected behavior when searching from a scope #1068

Open
vanboom opened this issue Jan 10, 2024 · 0 comments
Open

Unexpected behavior when searching from a scope #1068

vanboom opened this issue Jan 10, 2024 · 0 comments

Comments

@vanboom
Copy link

vanboom commented Jan 10, 2024

This may be more of a feature request than a bug/issue. Please consider:

User.where(country: "Finland").search("... elastic query here ...").records

This query executes fine, but the where condition is not considered.

User.where(country: "Finland").search("... elastic query here ...").records.to_sql
> "select users.* from users where id in (163, 511)"
Viewing the search results confirm this -- the country condition is not being applied. 

The same thing happens with scopes...

class User
  scope  :finnish, -> {where(country: "Finland")}
end

irb> User.finnish.search("... elastic query...").records

Shows the same result.

I am attempting to understand how the SQL gets built in elasticsearch-model to see if this might be a possibility to implement supporting the scope chaining. It may be worth some mention in the docs about this that the elasticsearch method must come first in the chain and all conditions should be applied on the proxy returned by the records method.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant