'How to update filed type from string to array of strings in elasticsearch?
I have an index filled by data with this schema:
{
"name" : "string",
"book": "string"
}
And I am working with ElasticSearch with Nest and C#. Now because of the business requirement book field must be an array and I Update my query model C# POCO class but when I run my query I am getting this error:
expected:'[', actual:'"test"', at offset:2248
Now I want to Update my schema to convert the book to array type. I try to use script and mapping but could not find a good solution? is there any working method to perform this change in ElasticSearch?
Solution 1:[1]
ES has built in functionally for docs update by query https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html.
In case above query will look like this:
POST my-index-000001/_update_by_query
{
"script": {
"source": " ctx._source.book = [ctx._source.book] ",
"lang": "painless"
},
"query": {
"match_all":{}
}
}
Solution 2:[2]
you cannot update or change field type in mapping(schema) of indices that has been created.
if you need change type, you should create new indices and use Reindex API.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nazar Mandzyk |
| Solution 2 | hamid bayat |
