1

My question is about changing a field type in my elasticsearch index using the elasticsearch ruby client chewy.

I am trying to update a field type in my index. I am getting this error: illegal_argument_exception.

I have read that it is impossible to change type in an existing index, so I was thinking about reindexing everything: rake chewy:reset. I have tried many things... I can't get my reindexation working.

The detailed error:

Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"mapper [enabled] cannot be changed from type [text] to [boolean]"}],"type":"illegal_argument_exception","reason":"mapper [enabled] cannot be changed from type [text] to [boolean]"},"status":400}

My index as it was before (field enabled was a texte, by default):

class SearchIndex < Chewy::Index
  define_type Company, delete_if: :deleted_at do
    ...
    field :enabled
    ...
  end
end

My index as I want it to be:

class SearchIndex < Chewy::Index
  define_type Company, delete_if: :deleted_at do
    ...
    field :enabled, type: 'boolean'
    ...
  end
end

How can I do with Chewy (without requesting to ElasticSearch via curl, if possible) to get my index reindexed with the new field type ?

Thanks.

Elie Teyssedou
  • 749
  • 1
  • 7
  • 19

2 Answers2

1

I haven't used Chewy before, but looking at the documentation you should just be able to call SearchIndex.reset! in a ruby console. Certainly deleting and recreating the index is possible and should be recreated from scratch with your new data type.

tombeynon
  • 2,216
  • 1
  • 20
  • 19
  • Thanks for answering my question. I tried it too and it doesn't work, I get the same error... Is it normal that Elasticsearch won't let me reindex/reset in my case ? How is it done without Chewy ? – Elie Teyssedou Oct 24 '18 at 14:54
  • What about `SearchIndex.purge!`? That should just recreate the index without reimporting, which might be where it's failing currently. Without Chewy you would need to use Curl to interact with the ES index, as per https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html – tombeynon Oct 25 '18 at 15:13
0

I found out why Elsaticsearch didn't wanted me to change my type. It was because my index got some other type containing the same field (at least the same field name), but with another field type.

So, all the field with the same name must have the same type. Then you will be able to (and you will have to) delete your index and recreate it. (SearchIndex::purge! does the job)

Elie Teyssedou
  • 749
  • 1
  • 7
  • 19