ElasticSearch not indexing custom fields on Cases module

I’ve found that the ElasticSearch indexing process does not pick up any values for a custom ‘purchaseorder_c’ field (in the cases_cstm database table).

I’ve been digging into this and I’ve made a few adjustments to try to get it to work.

My custom/Extension/modules/Cases/Ext/Vardefs/_override_sugarfield_purchaseorder_c.php:

<?php
 // created: 2022-11-11 16:06:04
$dictionary['Case']['fields']['purchaseorder_c']['inline_edit']='1';
$dictionary['Case']['fields']['purchaseorder_c']['labelValue']='PO';
$dictionary['Case']['fields']['purchaseorder_c']['unified_search']=true;
$dictionary['Case']['fields']['purchaseorder_c']['type']='varchar';

 ?>

I noticed that even with these set I could not get the cache at cache/modules/unified_search_modules.php to include any Case fields.

First I noticed there was no modules/Cases/metadata/metafiles.php like there was for Accounts at modules/Accounts/metadata/metafiles.php (is this a bug?) so I created one.

Then I found that the lib/Search/SearchModules buildCache function was not finding any ‘unified_search’ entries for Cases. It looks like the cause is that the $beanName for cases is ‘aCase’ and not ‘Case’ which is what’s in the global dictionary (I think this is a bug?). I added a conditional to reassign the $beanName as ‘Case’ if it was found to be ‘aCase’ before checking

 if($beanName == 'aCase') {
    $beanName = 'Case';
}
// If the bean supports unified search or if it's a custom module bean and unified search is not defined
if (!empty($dictionary[$beanName]['unified_search']) || $isCustomModule) {

I don’t see an issue with my fix but perhaps it’s not complete.

Regardless, I was now getting the Case fields in the cache/modules/unified_search_modules.php cache.

Now the issue I’m having is that no values for the custom field is getting pulled into the beans used for indexing. This makes it so that field gets stripped out in the lib/Utility/BeanJsonSerializer.php toArray function. The result is that the ElasticSearch index doesn’t add a mapping for that field.

I’ve been trying to make my way through the BeanFactory and whatnot to try to see what could be causing the custom Cases purchaseorder_c field to not produce a value when queried.

Interestingly, custom fields in Accounts are indexed properly in ElasticSearch. This makes me wonder if there’s another ‘aCase’/‘Case’ issue somewhere.

Can anyone provide any insight into a setting I need to adjust or maybe a place to look for further troubleshooting?

Thanks!

I don’t know the exact logic that is followed, but my bet would be that there is some generic file that it falls back on, and from a quick search I would bet it’s something from include/SugarObjects/templates/

The Case/aCase mess is an unfortunate, very old problem inherited from SugarCRM. I am not surprised that despite all the places where that logic appears ( if($beanName == 'aCase') { $beanName = 'Case';) you were able to still find a place where it has been missing all along, and that more are left to be found…