How to set elastic search custom field type?
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
How to set elastic search custom field type?
Laravel framework version: 10.16.1
Aimeos Laravel version: 2023.04.*
PHP Version: 10.46.0
Environment: Linux
Hello,
I want to set a custom field to be of type "date" in the elastic search mappings.
The reason behind this is because filtering results based on date breaks with custom attributes added to the decorator.
I found the configuration file here:
/vendor/aimeoscom/ai-elastic/setup/default/elastic
I added my own mapping and it works:
'myfield' => [ 'type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss' ]
I want to know how to add this mapping the correct way, so it won't disappear when updating the package.
Best regards
Aimeos Laravel version: 2023.04.*
PHP Version: 10.46.0
Environment: Linux
Hello,
I want to set a custom field to be of type "date" in the elastic search mappings.
The reason behind this is because filtering results based on date breaks with custom attributes added to the decorator.
I found the configuration file here:
/vendor/aimeoscom/ai-elastic/setup/default/elastic
I added my own mapping and it works:
'myfield' => [ 'type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss' ]
I want to know how to add this mapping the correct way, so it won't disappear when updating the package.
Best regards
Re: How to set elastic search custom field type?
Create e.g. a ./setup/default/elastic/product.php in your own extension and add your new field there:
Code: Select all
return array(
'base' => function ( array $mappings ) {
$map = [
'base' => [
'properties' => [
'myfield' => [ 'type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss' ]
],
],
];
return array_replace_recursive( $mappings, $map );
},
Re: How to set elastic search custom field type?
Thank you @nos3, works great
Code: Select all
<?php
return [
'base' => function( array $mappings ) {
$map = [
'base' => [
'properties' => [
'myfield' => [ 'type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss' ]
]
]
];
return array_replace_recursive( $mappings, $map );
}
];