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 reset breaks with ignore_blank option #842

Closed
bowenzhou222 opened this issue Apr 5, 2022 · 0 comments · Fixed by #843
Closed

Chewy reset breaks with ignore_blank option #842

bowenzhou222 opened this issue Apr 5, 2022 · 0 comments · Fixed by #843

Comments

@bowenzhou222
Copy link

Expected behavior

chewy:parallel:reset should work properly with the ignore_blank option

Actual behavior

It breaks with the following error:

[{"type":"mapper_parsing_exception","reason":"unknown parameter [ignore_blank] on mapper [xxx] of type [xxx]"}]

Steps to reproduce the problem

Create a simple index with "ignore_blank" option for any field:

class UsersIndex < Chewy::Index
  index_scope User
  field :name, ignore_blank: true
end

When run bin/rake chewy:parallel:reset\[user\], the actual payload sent to ES api will contain the "ignore_blank" field which is not accepted by ES:

"mappings": {
    "properties": {
      "name": {
        "type": "text",
        "ignore_blank": true
      },
}

I tried the following monkey patch and it seems to fix the bug:

    module Chewy
      module Fields
        class Base
          def mappings_hash
            mapping =
                if children.present?
                  {(multi_field? ? :fields : :properties) => children.map(&:mappings_hash).inject(:merge)}
                else
                  {}
                end
            mapping.reverse_merge!(options.except(:ignore_blank)) # here I have to remove "ignore_blank" from "options"
            mapping.reverse_merge!(type: (children.present? ? 'object' : Chewy.default_field_type))

            {name => mapping}
          end
        end
      end
    end

Version Information

v7.2.0

rabotyaga added a commit to rabotyaga/chewy that referenced this issue Apr 11, 2022
AlexVPopov pushed a commit to rabotyaga/chewy that referenced this issue Apr 27, 2022
cyucelen pushed a commit to cyucelen/chewy that referenced this issue Jan 28, 2023
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

Successfully merging a pull request may close this issue.

1 participant