Here is a quick solution to add the not_analyzed index to elasticsearch via wordpress. I’m doing it here on the init to make sure it is taken into consideration. This is just an example, you can add some conditions to make it better performance-wise :
if ( is_plugin_active('fantastic-elasticsearch/elasticsearch.php') ) :
add_action( 'init', 'prepare_mapping' );
endif;
function prepare_mapping()
{
$index_exists = elasticsearch\Api::option('server_index');
if ( $index_exists ) {
try {
$elasticaType = elasticsearch\Api::index(true)->getType('post');
$mapping_data = $elasticaType->getMapping();
$mapping_data = $mapping_data['post']['properties'];
$mapping_data['your_field']['type'] = 'string';
$mapping_data['your_field']['index'] = 'not_analyzed';
$mapping = new \Elastica_Type_Mapping();
$mapping->setType($elasticaType);
$mapping->setProperties($mapping_data);
$mapping->send();
} catch(Exception $e) {
//Do nothing, just make sure the error is not showing
}
}
}