# `search.reindex_failed`

An entity's index couldn't be rebuilt in its engine, because nothing sets the engine's settings, the database or the engine can't be reached, or the engine refused a record.

Area 14, [Tools](/docs/tooling.md); not declinable; the next step is usually the human's.

## Why Jadpo refuses it

`jadpo search reindex <Entity>` sends each record's document to the
search engine through the app's own connection, with that connection's
address and credential, read as `jadpo dev` reads them. Without them,
the only thing it could send is a stand-in key to a guessed address, so
it sends nothing.

When the database can't be read, or the engine refuses a record or can't
be reached, it stops there and says how many records it sent. Sending a
record's document again changes nothing, so the reindex can always be
run again from the start; it never empties the index.

Jadpo won't set a credential or pick a database for you: which engine
and which database it reaches may be production's, and only you know
which is right.

## What it looks like

A shop whose product names are kept in an index at Acme Search, through
the app's own package for it:














domains/shop/entities/product.jadpo:

```jadpo
use shop/types { ProductName }

/// Something the shop sells, its name kept in Acme's index.
entity Product {
    id: Uuid
    name: ProductName

    policy: {
        read: [Access.public]
    }

    search: {
        fields: [name]
        language: SearchLanguage.english
        store: products_index
    }
}
```

Nothing sets the index's address or its key:

```sh
jadpo search reindex Product
```

```text
error: `products_index` has nothing set for the engine
  reason: A reindex sends `Product`'s records through `products_index`, with its address and credential, and nothing sets `SEARCH_HOST` and `SEARCH_TOKEN`.
  next: Set `SEARCH_HOST` and `SEARCH_TOKEN` to the engine's, then run it again (human)
  rule: search.reindex_failed
  help: https://jadpo.dev/docs/errors/search.reindex_failed
```

`(human)` at the end of the `next:` line tells your coding agent to stop
and ask you which fix you want, because the choice is yours to make: the
key decides which account at the provider is reached, and it is a secret
only you hold.

A database whose server isn't running gives the same error, saying it
can't be reached. Here `DATABASE_URL` names a port where no server is
listening:

```sh
SEARCH_HOST=https://search.example.com SEARCH_TOKEN=token DATABASE_URL=postgresql://localhost:5499/shop jadpo search reindex Product
```

```text
error: The database `main` can't be reached
  reason: Connecting to it failed, so no records of `Product` could be read.
  next: Check the database is running and its address is right, then run the command again (human)
  rule: search.reindex_failed
  help: https://jadpo.dev/docs/errors/search.reindex_failed
```

An engine that refuses a record, or doesn't answer, stops the reindex
the same way, saying how many records were sent before it did.

## How to fix it

**If nothing sets the engine's settings**, set them to the engine the
app uses, in the environment or, at a prompt, in `.env.local`, then run
it again:

```sh
jadpo config set search_host
jadpo config set search_token
jadpo search reindex Product
```

It sends each product's document to that index and says how many it
sent.

**If the database or the engine can't be reached**, start it, or check
its address and credential, then run the command again from the start:

```sh
jadpo search reindex Product
```

Records already sent are sent again, which changes nothing.

**If the address names another database than the one the records are
in**, name that one with `--url`:

```sh
jadpo search reindex Product --url "$PRODUCTION_DATABASE_URL"
```

The command reads that database's records instead.

## Related

- [`jadpo search reindex`](/docs/commands-for-batches-deploys-and-search-indexes.md#jadpo-search-reindex)
- [An engine instead of PostgreSQL](/docs/search.md#an-engine-instead-of-postgresql)
- [How a package provides a capability](/docs/capabilities.md#how-a-package-provides-a-capability)
