Extending Search Index
Extending Search Index via Events
The regular index update process stores a defined set of standard data types in the data index which makes it possible to find, filter, sort and list them..
It is possible to extend the index with custom attributes if needed. For this purpose the following events exist. You will find code examples below.
UpdateIndexDataEvent
This event can be used to store additional fields in the search index. Depending on if you would like to index additional data for assets or data objects use one of the following two events.
Pimcore\Bundle\GenericDataIndexBundle\Event\Asset\UpdateIndexDataEvent
(assets)Pimcore\Bundle\GenericDataIndexBundle\Event\DataObject\UpdateIndexDataEvent
(concrete data object classes)Pimcore\Bundle\GenericDataIndexBundle\Event\DataObject\UpdateFolderIndexDataEvent
(data object folders)Pimcore\Bundle\GenericDataIndexBundle\Event\Document\UpdateIndexDataEvent
(documents)
If you take a look at the source of an indexed document within search index you will find a structure like this:
{
"system_fields" : {
"id" : 145,
"creationDate" : "2019-05-24T15:42:20+0200",
"modificationDate" : "2019-08-23T15:15:54+0200",
"type" : "image",
"key" : "abandoned-automobile-automotive-1082654.jpg",
...
},
"standard_fields" : [ ... ],
"custom_fields" : [ ]
}
This is used to separate the data into three sections:
system_fields
Base system fields which are the same for all assets or data objects (like id, creationDate, fullPath...).