Problem/Motivation
Changing field types gives the following error:
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"mapper [title] cannot be changed from type [text] to [keyword]"}],"type":"illegal_argument_exception","reason":"mapper [title] cannot be changed from type [text] to [keyword]"},"status":400}
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3266032-9.patch | 419 bytes | kim.pepper |
Issue fork search_api_opensearch-3266032
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3266032-cannot-change-field
changes, plain diff MR !6
Comments
Comment #2
kim.pepperAccording to the docs, you can only update field types _before_ any data is indexed.
I think the best we can do is catch this error and display a helpful message to the user.
Comment #3
kim.pepperSee https://opensearch.org/docs/latest/opensearch/rest-api/update-mapping/
Comment #4
kim.pepperWe might be able to use
\Drupal\search_api\Item\FieldInterface::setTypeLocked()to indicate the field type cannot be changed.Comment #5
acbramley commentedSo it is possible to change field mappings if you clear the index and re-index everything. The issue is that once you change a field mapping search_api adds a new task to the DB to update that mapping. Doing any other action on the index tries to execute that task first which results in an exception and doesn't delete the task. It means that it's impossible to clear the index after changing a field's type. The only workaround currently is to manually delete all tasks (e.g
delete from search_api_task;) and then clear the index. After doing that you're able to index again with the new field mapping.I wonder if we can simply hook into the updateMapping process and re-create the index first?
Comment #7
kim.pepperAdd a reindex() call when updating the mapping.
Comment #8
kim.pepperMarking for reindex isn't enough. We need to recreate in the index.
Comment #9
kim.pepperTesting a patch file.
Comment #10
acbramley commentedWorks for me!
Comment #12
kim.pepperCommitted and pushed to 1.x. Thanks!