Skip to main content
Version: Next

Searching For Data In Index

The Generic Data Index bundle provides standardized search services for querying assets, data objects, and documents from the search indices.

Each search uses a type-specific search service and a search model that defines the query. Create search models with the SearchProviderInterface.

Load all assets from the root folder (parent ID 1), ordered by full path:

use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Asset\AssetSearchServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\ParentIdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath;

public function searchAction(
SearchProviderInterface $searchProvider,
AssetSearchServiceInterface $assetSearchService
) {
$assetSearch = $searchProvider->createAssetSearch()
->addModifier(new ParentIdFilter(1))
->addModifier(new OrderByFullPath())
->setPageSize(50)
->setPage(1);

$searchResult = $assetSearchService->search($assetSearch);
}

Load all data objects from the root folder for a specific class definition, ordered by full path:

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\ParentIdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\DataObject\DataObjectSearchServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface;
use Pimcore\Model\DataObject\ClassDefinition;

public function searchAction(
SearchProviderInterface $searchProvider,
DataObjectSearchServiceInterface $dataObjectSearchService
) {
$carClassDefinition = ClassDefinition::getByName('Car');

$dataObjectSearch = $searchProvider->createDataObjectSearch()
->addModifier(new ParentIdFilter(1))
->addModifier(new OrderByFullPath())
->setClassDefinition($carClassDefinition)
->setPageSize(50)
->setPage(1);

$searchResult = $dataObjectSearchService->search($dataObjectSearch);
}

Load all documents from the root folder, ordered by full path:

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\ParentIdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Document\DocumentSearchServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface;

public function searchAction(
SearchProviderInterface $searchProvider,
DocumentSearchServiceInterface $documentSearchService
) {
$documentSearch = $searchProvider->createDocumentSearch()
->addModifier(new ParentIdFilter(1))
->addModifier(new OrderByFullPath())
->setPageSize(50)
->setPage(1);

$searchResult = $documentSearchService->search($documentSearch);
}

Element Search (Cross-Type)​

The element search queries assets, data objects, and documents simultaneously.

info

The element search does not compute hasChildren attributes. hasChildren always returns false for all elements in element search results.

Load all elements required by asset ID 123, ordered by full path:

use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\ElementType;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Dependency\RequiredByFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Element\ElementSearchServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface;

public function searchAction(
SearchProviderInterface $searchProvider,
ElementSearchServiceInterface $elementSearchService
) {
$elementSearch = $searchProvider->createElementSearch()
->addModifier(new RequiredByFilter(123, ElementType::ASSET))
->addModifier(new OrderByFullPath())
->setPageSize(50)
->setPage(1);

$searchResult = $elementSearchService->search($elementSearch);
}

Use the FullTextSearch modifier for full-text queries. It supports the following options:

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\FullTextSearch;

new FullTextSearch(
$term,
defaultOperator: 'AND', // 'AND' (default) requires all terms, 'OR' matches any
fields: [], // limit to specific fields (with optional boosts), e.g. ['system_fields.key^3']
flags: 'PHRASE|WHITESPACE', // enabled simple_query_string operators; null/'ALL' enables all of them
);

By default, characters like - and . are treated as literal text (not as operators), and double quotes enable phrase search.

Note on partial matches of values containing punctuation (e.g. version numbers or SKUs like 1.1.1): partial matching is powered by an n-gram analyzer whose tokenizer only keeps letters and digits by default, so punctuation splits the value. As a result, searching 1.1 does not match 1.1.1. To enable this, extend the n-gram tokenizer's token_chars (e.g. add punctuation and symbol) via index_service.index_settings and re-index. See Index Management.

Search Modifiers​

Search modifiers filter, sort, and aggregate search results. See the Search Modifiers documentation for the full reference and instructions on creating custom modifiers.

Retrieving IDs Only​

Use SearchResultIdListServiceInterface to retrieve search results as ID lists instead of full objects:

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\ParentIdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchResultIdListServiceInterface;

public function searchAction(
SearchProviderInterface $searchProvider,
SearchResultIdListServiceInterface $searchResultIdListService
) {
$dataObjectSearch = $searchProvider->createDataObjectSearch()
->addModifier(new ParentIdFilter(1))
->addModifier(new OrderByFullPath())
->setPageSize(50)
->setPage(1);

// All IDs for the full search result (ignoring pagination)
$allIds = $searchResultIdListService->getAllIds($dataObjectSearch);

// IDs for the current page only
$idsOnPage = $searchResultIdListService->getIdsForCurrentPage($dataObjectSearch);
}

Default Search Models​

To build custom OpenSearch/Elasticsearch queries beyond what the search services offer, use default search models. The search services use these models internally.

See the Default Search Models documentation.

Permissions​

The search services respect user permissions and workspace configurations.

See Permissions and Workspaces.

Workflow Places​

The current places of workflows using the state_table marking store are indexed in the keyword system field system_fields.workflowPlaces.<workflow name>, with one value per place. The places are indexed as stored in element_workflow_state, independent of the support strategy of the workflow, so a search can filter by the place of a workflow that is not visible to the searching user. Elements without a stored place (for example elements created before the workflow was configured) have no value: the initial place is not assumed. Other marking stores keep the place in an element field, which is indexed like any other field.

system_fields.workflowPlaces.product_workflow = "review"

When a place changes without saving the element (transitions, global actions or the initial place), the element is added to the index queue. This happens at the end of the request, the console command or the messenger message, not when the place changes, so a place which is rolled back by a failing save is not indexed, and a long-running command that only applies transitions updates the index when it ends. This relies on the workflow.entered event, so keep it in events_to_dispatch if a workflow restricts the dispatched events.

Transitions that only save a version (changePublishedState: save_version) do not save the element, so their place reaches the index with the queue even if synchronous processing is enabled.

After adding or removing a state_table workflow, restart the messenger consumers (for example with bin/console messenger:stop-workers) and other long-running PHP processes, because they read the workflows once. Then run bin/console generic-data-index:update:index to update the mapping and fill the field for existing elements.

Pimcore Query Language (PQL)​

PQL defines a query syntax for searching data objects, assets, and documents.

Debug Search Queries​

When debug mode is enabled, add the debug-search-queries GET parameter to any URL to inspect the executed search queries:

ValueOutput verbosity
1Normal
2Verbose
3Very verbose

The response is replaced with the search query output.