Indexing API
index_bulk transforms entities with format_entity and bulk-indexes them with an Indexer. The indexer is tuned by the indexing settings.
from followthemoney import model
from openaleph_search.index.entities import index_bulk
entity = model.make_entity("Person")
entity.id = "jane-doe"
entity.add("name", "Jane Doe")
stats = index_bulk("my_dataset", [entity], sync=True)
With index_namespace_ids (the default) the indexed ID is signed with the dataset, so look entities up by the IDs a search returns.
Write
openaleph_search.index.entities.index_bulk(dataset, entities, sync=False, **kwargs)
Transform and index entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str
|
Dataset of the entities. |
required |
entities
|
Iterable[EntityLike]
|
Proxies, |
required |
sync
|
Refresh, so the entities are searchable on return. |
False
|
|
**kwargs
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
IndexStats
|
Counts of the run. |
openaleph_search.index.entities.index_proxy(dataset, proxy, sync=False, **kwargs)
Index one entity and delete it from the indexes of other schemata, with
the short max_retries budget of a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str
|
Dataset of the entity. |
required |
proxy
|
EntityProxy
|
The entity. |
required |
sync
|
Refresh, so the entity is searchable on return. |
False
|
|
**kwargs
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
IndexStats
|
Counts of the run. |
openaleph_search.index.entities.delete_entity(entity_id, exclude=None, sync=False)
Delete an entity from the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
The entity ID. |
required | |
exclude
|
Keep it in the write index of this schema. |
None
|
|
sync
|
Refresh, so the deletion is visible on return. |
False
|
openaleph_search.index.indexer.Indexer(dataset=None, chunk_size=None, batch_bytes=None, concurrency=None, sync=False, max_retries=None, **context)
Transform entities and bulk-index them from a single process: the transform runs inline while the bulk requests are in flight.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str | None
|
Dataset of the entities, required by |
None
|
chunk_size
|
int | None
|
Entities per batch, defaults to |
None
|
batch_bytes
|
int | None
|
Payload bytes per batch, defaults to |
None
|
concurrency
|
int | None
|
Upper bound on bulk requests in flight, defaults to
|
None
|
sync
|
bool | None
|
Refresh, so the entities are searchable on return. |
False
|
max_retries
|
int | None
|
Retries of a rejected batch, defaults to
|
None
|
**context
|
Any
|
Passed to
|
{}
|
index(entities)
Transform and index a stream of entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
Iterable[EntityLike]
|
Proxies, |
required |
Returns:
| Type | Description |
|---|---|
IndexStats
|
Counts of the run. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the indexer has no |
index_actions(actions)
Index a stream of already formatted actions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions
|
Actions
|
Bulk actions, e.g. from
|
required |
Returns:
| Type | Description |
|---|---|
IndexStats
|
Counts of the run. |
openaleph_search.index.indexer.IndexStats
Bases: NamedTuple
Outcome of an indexing run.
Attributes:
| Name | Type | Description |
|---|---|---|
indexed |
int
|
Documents indexed. |
failed |
int
|
Documents rejected for good. |
took |
timedelta
|
Duration of the run. |
Read
openaleph_search.index.entities.get_entity(entity_id, **kwargs)
Fetch an entity from the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
The entity ID. |
required | |
**kwargs
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
|
The entity, or |
openaleph_search.index.entities.entities_by_ids(ids, schemata=None, cached=False, includes=PROXY_INCLUDES, excludes=None)
Iterate over the entities with the given IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
One or more entity IDs. |
required | |
schemata
|
Only look in the buckets of these schemata. |
None
|
|
cached
|
Not implemented, logs a warning. |
False
|
|
includes
|
|
PROXY_INCLUDES
|
|
excludes
|
|
None
|
Yields:
| Type | Description |
|---|---|
|
Entities as |
openaleph_search.index.entities.iter_entities(auth=None, dataset=None, collection_id=None, schemata=None, includes=PROXY_INCLUDES, excludes=None, filters=None, sort=None, es_scroll='5m', es_scroll_size=1000)
Scan all entities matching the given criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
SearchAuth | None
|
Only the datasets it may read. |
None
|
dataset
|
str | None
|
Only this dataset; ignored with |
None
|
collection_id
|
str | None
|
Only this collection. |
None
|
schemata
|
Only entities of these schemata or their descendants. |
None
|
|
includes
|
|
PROXY_INCLUDES
|
|
excludes
|
|
None
|
|
filters
|
More Elasticsearch filter clauses. |
None
|
|
sort
|
Sort to scan in; unsorted scans are faster. |
None
|
|
es_scroll
|
Lifetime of the scroll context. |
'5m'
|
|
es_scroll_size
|
Hits per scroll page. |
1000
|
Yields:
| Type | Description |
|---|---|
|
Entities as |
openaleph_search.index.entities.get_entity_content(entity_id)
Fetch the indexed fulltext of a Document or Pages entity: its
bodyText, or the stored content of the pages bucket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
The entity ID. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The text joined by newlines, or |
Transform
openaleph_search.transform.entity.format_entity(dataset, entity, **kwargs)
Transform an entity into a bulk index action. Trusted entity data (an
EntityPayload or a dict) is transformed without building a proxy; the
input is not modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str
|
Dataset of the entity. |
required |
entity
|
EntityLike
|
A proxy, an |
required |
**kwargs
|
|
{}
|
Returns:
| Type | Description |
|---|---|
Action | None
|
The action, or |
openaleph_search.transform.entity.format_entities(dataset, entities, **kwargs)
Lazily transform a stream of entities into index actions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str
|
Dataset of the entities. |
required |
entities
|
Iterable[EntityLike]
|
Proxies, |
required |
**kwargs
|
Passed to |
{}
|
Yields:
| Type | Description |
|---|---|
Actions
|
Actions, skipping entities of abstract schemata. |
openaleph_search.transform.entity.iter_batches(entities, chunk_size=None, batch_bytes=None)
Batch a stream of entities by count and by payload bytes (estimated by
entity_size), cutting on whichever bound is reached first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
Iterable[EntityLike]
|
Proxies, |
required |
chunk_size
|
int | None
|
Entities per batch, defaults to |
None
|
batch_bytes
|
int | None
|
Payload bytes per batch, defaults to |
None
|
Yields:
| Type | Description |
|---|---|
list[EntityLike]
|
Lists of entities. |