I’m using Elasticsearch v2.1.1. I have indexed a data set in it with some fields like keywords, Collection etc.
My sample indexed dataset is as follows:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 103,
"max_score": 1,
"hits": [
{
"_index": "pibtest1",
"_type": "SearchTech",
"_id": "http://www.searchtechnologies.com/images/solutions/candidate-search-match-dashboard.PNG",
"_score": 1,
"_source": {
"Collection": "default_collection",
"keywords": "keywords-NOT-PROVIDED"
}
}
}
}
Now I want to append comma separated values to the Collection field.
For eg: “Collection”:[ “default_collection”,”wiki_collection”]
Right now, the Collection field is of type “string”. I believe the Collection field needs to be of type array for this. So shall I create an array type mapping before indexing the data in ES? If yes, how shall I do it? I have tried to create the mapping (before indexing the data) like below but it didn’t work and gave me an error.
PUT pibtest1
{
"mappings":{
"SearchTech": {
"properties": {
"Collection" :{
"type": "array",
"index": "analyzed"
}
}
}
}
}
Error:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "No handler for type [array] declared on field [Collection]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [SearchTech]: No handler for type [array] declared on field [Collection]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "No handler for type [array] declared on field [Collection]"
}
},
"status": 400
}
How do I use the _update api for this? I read that update api will replace the existing value with the new value but I need to append the value to the array. I want to search for a query and update the Collection fields of the results. Thank you.
I found this similar post: Append to an existing elasticsearch array field using python