---
title: Discovery
slug: klevu-magento-v4/entities-discovery
docTags: 
createdAt: 2024-08-06T15:22:41.416Z
---

## Entity Discovery

:::hint{type="warning"}
Entity discovery does not send any data via the API to Klevu.&#x20;

Its only purpose is to add missing entities to the `klevu_indexing_entity` database table or to set entities that are no longer indexable to have a `next action` of `Delete`.
:::

Note: all Magento category, CMS page and product entities are added here, even if they do not currently need to be indexed with Klevu.

Entity discovery will:

- add any missing entities and determine if those entities are indexable.
- set any entities which are no longer indexable, but were previously registered, to have a `next_action` of `Delete`.
- set any entities that have become indexable to have a `next_action` of `Add`.

Entity discovery will **NOT**:

- determine if an entity requires an update.
- send any data to Klevu.

Entity discovery is triggered:

- on account integration
- via plugins
- via observers
- via cron
- via CLI

`\Klevu\Indexing\Service\EntityDiscoveryOrchestratorService`is responsible for entity discovery. All the above methods of triggering entity discovery use this service.

### Cron

:::hint{type="info"}
As with all cron tasks added by version 4.x of the Klevu integration, entity discovery cron tasks use the dedicated `klevu` group, allowing granular configuration of scheduling and run options.

We recommend using the native Magento cron to run these jobs, configuring schedules if necessary, rather than a custom server-side cron implementation of the CLI command.
:::

Entity discovery runs once a day via cron.
The configuration for the cron can be found here `module-m2-indexing/etc/crontab.xml`

:::CodeblockTabs
module-m2-indexing/etc/crontab.xml

```xml
<job name="klevu_indexing_discover_entities"
     instance="Klevu\Indexing\Cron\DiscoverEntities"
     method="execute">
    <schedule>0 2 * * *</schedule>
</job>
```
:::

### CLI

`klevu:indexing:entity-discovery`

The discovery can also be triggered via CLI and has 2 optional parameters

- `api-keys` - \[optional] comma-separated list of API keys to run discovery for
- `entity-types` - \[optional] comma-separated list of entity types to run discovery for,
  options:
  - `KLEVU_PRODUCT`
  - `KLEVU_CATEGORY`
  - `KLEVU_CMS`

e.g

```shell
bin/magento klevu:indexing:entity-discovery \
    --entity-types="KLEVU_PRODUCT" \
    --api-keys="klevu-example-js-api-key"

```

:::hint{type="info"}
The module does not depend on the `updated_at` for a discovery operation.
:::

