Hi,
Am not an Expert on elastic search but would like to update around 2 million records in my database with a country prefix to be added to the phone number field in correct format.
My phone number field lies under nested fields. The data is store in below structure
"contact" : [
{
"contactIdentifier" : {
"id" : "xxxxx"
},
"contactMedium" : [
{
"PhoneNumber" : {
"countryPrefix" : "21",
"phoneNumber" : "2147000000",
"nationalNumber" : "47000000"
}
},
{
"emailAddress" : "hilxxxrs@tvvvv.bggg",
"cmIdentifier" : "266k7382873115286"
}
]
}
]
i would like to update data for "phoneNumber" : "2147000000" to "phoneNumber" : "002147000000"
I tried with the below query to update the data but it did not work
POST /search_party_reindex_v2/_update_by_query
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "contact.contactMedium",
"query": {
"exists": {
"field": "contact.contactMedium.PhoneNumber.phoneNumber"
}
}
}
}
],
"must_not": [
{
"nested": {
"path": "contact.contactMedium",
"query": {
"wildcard": {
"contact.contactMedium.PhoneNumber.phoneNumber": {
"value": "00*"
}
}
}
}
}
]
}
},
"script": {
"script": "ctx._source.contact?.each { obj -> if (obj != null && obj.contactMedium != null) { obj.contactMedium?.each{cm -> if(cm.PhoneNumber.phoneNumber != null) ctx._source.contact.contactMedium.PhoneNumber.phoneNumber -= params.prefix + ctx._source.contact.contactMedium.PhoneNumber.phoneNumber}}};",
"lang": "painless",
"params": {
"prefix": "00"
}
}
}
Can any one help me on this
Thanks
Meena