Search Manager

class elasticgit.search.ESManager(storage_manager, es, index_prefix)[source]

An interface to elasticgit.models.Model instances stored in Git.

Parameters:
create_index(name)[source]

Creates the index in Elasticsearch

Parameters:name (str) –
destroy_index(name)[source]

Destroys the index in Elasticsearch

Parameters:name (str) –
get_mapping(name, model_class)[source]

Retrieve a mapping for a model class in a specific index

Parameters:
Returns:

dict

index(model, refresh_index=False)[source]

Index a elasticgit.models.Model instance in Elasticsearch

Parameters:
  • model (elasticgit.models.Model) – The model instance
  • refresh_index (bool) – Whether or not to manually refresh the Elasticsearch index. Useful in testing.
Returns:

elasticgit.models.Model

index_exists(name)[source]

Check if the index already exists in Elasticsearch

Parameters:name (str) –
Returns:bool
index_name(name)[source]

Generate an Elasticsearch index name using given name and prefixing it with the index_prefix. The resulting generated index name is URL quoted.

Parameters:name (str) – The name to use for the index.
index_ready(name)[source]

Check if an index is ready for use.

Parameters:name (str) –
Returns:bool
index_status(name)[source]

Get an index status

Parameters:name (str) –
raw_unindex(model_class, uuid, refresh_index=False)[source]

Remove an entry from the Elasticsearch index. This differs from unindex() because it does not require an instance of elasticgit.models.Model because you’re likely in a position where you don’t have it if you’re trying to unindex it.

Parameters:
  • model_class (elasticgit.models.Model) – The model class
  • uuid (str) – The model’s UUID
  • refresh_index (bool) – Whether or not to manually refresh the Elasticsearch index. Useful in testing.
refresh_indices(name)[source]

Manually refresh the Elasticsearch index. In production this is not necessary but it is useful when running tests.

Parameters:name (str) –
setup_custom_mapping(name, model_class, mapping)[source]

Specify a mapping for a model class in a specific index

Parameters:
Returns:

dict

setup_mapping(name, model_class)[source]

Specify a mapping for a model class in a specific index

Parameters:
Returns:

dict

unindex(model, refresh_index=False)[source]

Remove a elasticgit.models.Model instance from the Elasticsearch index.

Parameters:
  • model (elasticgit.models.Model) – The model instance
  • refresh_index (bool) – Whether or not to manually refresh the Elasticsearch index. Useful in testing.
Returns:

elasticgit.models.Model

class elasticgit.search.SM(model_class, in_, index_prefixes=None)[source]

A search interface similar to elasticutils.S to retrieve elasticgit.search.ReadOnlyModelMappingType instances stored in Elasticsearch. These can be converted to elasticgit.model.Model instances using ReadOnlyModelMappingType.to_object().

Parameters:
  • model_class (type) – A subclass of elasticgit.models.Model for generating a mapping type.
  • in (list) – A list of git.Repo instances, or a list of repo working dirs.
  • index_prefixes (list) – An optional list of index prefixes corresponding to the repos in in_.
get_repo_indexes()[source]

Generate the indexes corresponding to the repos.

Returns:list
elasticgit.search.index_name(prefix, name)[source]

Generate an Elasticsearch index name using given name and prefixing it with the given index_prefix. The resulting generated index name is URL quoted.

Parameters:
  • prefix (str) – The prefix to use for the index.
  • name (str) – The name to use for the index.
Returns:

str