The error occurs as ElasticSearch determines the type of a field once the first non empty value is defined. So if a BusinessData object with `long expensesPtCurrent` is once persistent, the type can be changed to `String` without facing compatiblity issues.
To takle the problem I'd write a conversion in Java to:
1. read old values (where the field was a long) as raw JSON
2. load and update the persistent businssData object and apply a compatible value in new format (String)
3. store the updated value in BusinessData repo
Sample:
public static void convertLegacy() throws IOException
{
ObjectMapper mapper = new ObjectMapper();
BusinessDataRepository repository = BusinessDataRepository.get();
List<BusinessDataInfo<Antrag>> infos = repository.search(Antrag.class).execute().getAllInfos();
for(BusinessDataInfo<Antrag> info : infos)
{
String json = BusinessDataSearchIndex.toSearchIndexJson(info.getRawValue());
JsonNode node = mapper.readTree(json); // JSON = simple API to work with JSON objects
JsonNode ptCurr = node.get("lohnUndOderArbeitszeitaenderung").get("expensesPtCurrent");
if (ptCurr.isLong())
{
// legacy value
long oldVal = ptCurr.asLong();
Antrag antrag = repository.find(info.getId(), Antrag.class);
antrag.setExpensesCurrent(String.valueOf(oldVal)+ " CHF");
repository.save(antrag);
}
}
}
To avoid the problem at all:
Do not change the type of already persistent data. But add a new replacement field. Optionally with fallback support to read legacy values. See: https://answers.axonivy.com/questions/2606/can-not-persist-business-data-to-repo-after-changing-data-type