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

Chewy::UnderivableType after upgrading to 7.0 #808

Closed
bordemof opened this issue Jul 28, 2021 · 10 comments
Closed

Chewy::UnderivableType after upgrading to 7.0 #808

bordemof opened this issue Jul 28, 2021 · 10 comments

Comments

@bordemof
Copy link

bordemof commented Jul 28, 2021

Actual behavior

After upgrading the chewy version to 7 started getting this error when I try to query I alway get this error,:

UsersIndex.limit(1)[0]
Chewy::UnderivableType (Index `users` doesn`t have type named `_doc`)

I dont have any mappings in the Index definition since its only a consumer class.

class UsersIndex < Chewy::Index

  index_name 'users'

end

Thanks in advance

Version Information

  • Chewy version :7.0
  • Elasticsearch version: 7.13.3
  • Ruby version 2.6.3
  • Rails version 6.1.3.1
@rabotyaga
Copy link
Contributor

Hey @bordemof 👋 !
What is this index_name directive?
In Chewy 7.0 you have to use define_type block and in Chewy >= 7.2.0 you have to use index_scope.

@bordemof
Copy link
Author

@rabotyaga Upgrading to 7.2 and changing to index_scope solved my issue thanks, but now it seems that some methods such as paginate are not available, any advise on how to perform pagination on 7.2 and above, Rubydocs for chewy seem to be down at this moment

@rabotyaga
Copy link
Contributor

What do you use for pagination?
Kaminari should work out of the box: https://github.com/toptal/chewy#pagination
will_paginate support was removed in 7.2.0 (see CHANGELOG)

@bordemof
Copy link
Author

bordemof commented Aug 2, 2021

@rabotyaga I just added Kaminari gem in order to get pagination working but total_count method doest not work, it gives the following error, visible its just a scoped query.

UsersIndex.visible.total_count
NoMethodError (undefined method `fetch' for 6367557:Integer)

After the changes you suggested and upgrading to 7.2 this is the index definition

class UsersIndex < Chewy::Index

  index_scope 'users'

end

@rabotyaga
Copy link
Contributor

@bordemof Do you use/append rest_total_hits_as_int option somewhere? The error you've mentioned looks like a hits.total issue. We have a detailed explanation of the problem and our approach to fix it in the migration guide:

The “total hits” counter is an integer for ES versions < 7 and an object (hash) for the versions starting from 7.0.0. Elasticsearch added a special option, rest_total_hits_as_int, to ease the upgrade, that could be appended to any request and results in the old “total hits” format. Unfortunately, this option is not recognized by ES versions prior to 7.0.0, which means that we have to check the version to decide if we need this option. Normally Chewy does memoization of the current ES version, but this might be inappropriate for the upgrade, as the version changes live. To handle that we have 2 versions of Chewy for this stage of the upgrade: 7.0.0 and 7.0.1. Version 7.0.0 does the memoization and version 7.0.1 requests the current version on every search request.

@bordemof
Copy link
Author

bordemof commented Aug 2, 2021

@rabotyaga You are most probably right, I assume that this should be present in all the queries that need a total result from now on. Its there any available example on how to include rest_total_hits_as_int in good way inside an index?

@rabotyaga
Copy link
Contributor

rabotyaga commented Aug 2, 2021

@rabotyaga You are most probably right, I assume that this should be present in all the queries that need a total result from now on. Its there any available example on how to include rest_total_hits_as_int in good way inside an index?

It's the opposite situation - since you're using ES version >= 7 and Chewy 7.2.2 this option is not needed, but the error

undefined method `fetch' for 6367557:Integer

looks like ElasticSearch continues to return hits.total as an integer, instead of a hash. This might happen, if you use some monkey patches to append this option similar to noellabo@94e8a6c or https://gist.github.com/Vincanote/2b18ba8aa33d068a9cc012b9a4d891af#file-gistfile1-txt-L21

@rabotyaga
Copy link
Contributor

@bordemof Did you manage to solve this? I've got an email regarding a new comment, but it's now deleted, that's why I'm asking.

@bordemof
Copy link
Author

bordemof commented Aug 3, 2021

Yes you were right, I was making some desperate tries looking to the solution people provided in other issues and I left a wrong config in one initializer. Now it works just by changing the index_scope thing and the pagination library @rabotyaga
Thanks a lot for the guidance.

@rabotyaga
Copy link
Contributor

Great! Glad to hear!

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

2 participants