Ejemplo n.º 1
0
class Aliases(object):
    """
    This class contains all the methods related to ElasticSearch alias management.
    """
    def __init__(self, host_name, port_number):
        """
        Instantiate object with the following parameters:
            host_name       ElasticSearch host name
            port_number     ElasticsSearch API port number
        """
        self.es_connection = Connection(host_name, port_number)

    def create_alias(self, alias_name, index_name):
        """
        Create an alias to the specified index.
            alias_name      The alias name to create
            index_name      The index the alias points to
        """
        es = self.es_connection.get_connection()
        result = es.indices.put_alias(name=alias_name,
                                      index=index_name,
                                      ignore=400)

        # Display error if there is one
        acknowledge_result(result)

    def delete_alias(self, alias_name, index_name):
        """
        Delete the specified alias from ElasticSearch.
            alias_name      The alias name to delete
            index_name      The index that the alias points to
        """
        es = self.es_connection.get_connection()
        result = es.indices.delete_alias(index=index_name, name=alias_name)

        # Display error if there is one
        acknowledge_result(result)

    def list_alias(self, index_name):
        """
        List the aliases defined on the ElasticSearch cluster.
            index_name      Name of index to list aliases (default is _all)
        """
        es = self.es_connection.get_connection()
        if not index_name:
            result = es.indices.get_aliases()
        else:
            result = es.indices.get_aliases(index=index_name)

        # Print an error if one occurred
        acknowledge_result(result)

    def show_alias(self, alias_name):
        """
        Show the details about the specified alias.
            alias_name      The name of the alias to show
        """
        print "Not implemented."
Ejemplo n.º 2
0
class Cluster(object):
    """
    This class provides access to ElasticSearch cluster management features.
    """

    def __init__(self, host_name, port_number):
        """
        Instantiate object with the following parameters:
            host_name       ElasticSearch host name
            port_number     ElasticsSearch API port number
        """
        self.es_connection = Connection(host_name, port_number)

    def cluster_health(self, index_name):
        """
        Display basic cluster health information, or if index is specified, of that index.
            index_name      Index to get health status on
        """
        es = self.es_connection.get_connection()
        if index_name == "_all":
            result = es.cluster.health()
        else:
            result = es.cluster.health(index=index_name)

        # Print an error if one occurred
        acknowledge_result(result)
Ejemplo n.º 3
0
class Mapping(object):
    """
    Provide functions for managing index mappings on an ElasticSearch cluster.
    """
    def __init__(self, host_name, port_number):
        """
        Instantiate object with the following parameters:
            host_name       ElasticSearch host name
            port_number     ElasticsSearch API port number
        """
        self.es_connection = Connection(host_name, port_number)

    def list_mapping(self, index_name):
        """
        Show the mappings for a specified index.
            index_name      Index to display mappings.
        """

        es = self.es_connection.get_connection()
        result = es.indices.get_mapping(index=index_name)

        # Display error if there is one
        acknowledge_result(result)
Ejemplo n.º 4
0
class Indices(object):
    """
    This class contains all the methods related to ElasticSearch index management.
    """

    def __init__(self, host_name, port_number):
        """
        Instantiate object with the following parameters:
            host_name       ElasticSearch host name
            port_number     ElasticsSearch API port number
        """
        self.es_connection = Connection(host_name, port_number)

    def create_index(self, index_name, shards, replicas):
        """
        Create an ElasticSearch index
            index_name      Name of index to be created
            shards          Number of shards for index
            replicas        Number of replicas for index
        """
        es = self.es_connection.get_connection()
        result = es.indices.create(
            index=index_name,
            body={
                'settings': {
                    'number_of_shards': shards,
                    'number_of_replicas' : replicas
                }
            },
            # Do not generate an error if index exists
            ignore=400
        )

        # Display error if there is one
        acknowledge_result(result)


    def delete_index(self, index_name):
        """
        Delete an ElasticSearch index
            index_name      Name of index to be deleted
        """
        es = self.es_connection.get_connection()
        result = es.indices.delete(index=index_name)

        # Display error if there is one
        acknowledge_result(result)

    def open_index(self, index_name):
        """
        Open a closed index in the ElasticSearch cluster
            index_name      Name of index to be opened
        """
        es = self.es_connection.get_connection()
        result = es.indices.open(index=index_name)

        # Display error if there is one
        acknowledge_result(result)

    def close_index(self, index_name):
        """
        Close an index on the ElasticSearch cluster
            index_name      Name of index to be closed
        """
        es = self.es_connection.get_connection()
        result = es.indices.close(index=index_name)

        # Print an error if one occurred
        acknowledge_result(result)

    def flush_index(self, index_name):
        """
        Flush all of the documents out of the target index
            index_name      Name of index to be flushed
        """
        es = self.es_connection.get_connection()
        result = es.indices.flush(index=index_name)

        # Print an error if one occurred
        acknowledge_result(result)

    def list_index(self, index_name):
        """
        Display a list of indices in the ElasticSearch cluster.
            index_name      Name of index to list (default is _all)
        """
        es = self.es_connection.get_connection()
        result = es.indices.get_settings(index=index_name)

        # Print an error if one occurred
        acknowledge_result(result)

    def show_stats(self, index_name):
        """
        Display performance metrics for specified index.
        """
        es = self.es_connection.get_connection()
        result = es.indices.stats(index_name)

        # Print an error if one occurred
        acknowledge_result(result)
Ejemplo n.º 5
0
class Aliases(object):
    """
    This class contains all the methods related to ElasticSearch alias management.
    """

    def __init__(self, host_name, port_number):
        """
        Instantiate object with the following parameters:
            host_name       ElasticSearch host name
            port_number     ElasticsSearch API port number
        """
        self.es_connection = Connection(host_name, port_number)

    def create_alias(self, alias_name, index_name):
        """
        Create an alias to the specified index.
            alias_name      The alias name to create
            index_name      The index the alias points to
        """
        es = self.es_connection.get_connection()
        result = es.indices.put_alias(
            name=alias_name,
            index=index_name,
            ignore=400
        )

        # Display error if there is one
        acknowledge_result(result)

    def delete_alias(self, alias_name, index_name):
        """
        Delete the specified alias from ElasticSearch.
            alias_name      The alias name to delete
            index_name      The index that the alias points to
        """
        es = self.es_connection.get_connection()
        result = es.indices.delete_alias(
            index=index_name,
            name=alias_name
        )

        # Display error if there is one
        acknowledge_result(result)

    def list_alias(self, index_name):
        """
        List the aliases defined on the ElasticSearch cluster.
            index_name      Name of index to list aliases (default is _all)
        """
        es = self.es_connection.get_connection()
        if not index_name:
            result = es.indices.get_aliases()
        else:
            result = es.indices.get_aliases(index=index_name)

        # Print an error if one occurred
        acknowledge_result(result)

    def show_alias(self, alias_name):
        """
        Show the details about the specified alias.
            alias_name      The name of the alias to show
        """
        print "Not implemented."
Ejemplo n.º 6
0
class Indices(object):
    """
    This class contains all the methods related to ElasticSearch index management.
    """
    def __init__(self, host_name, port_number):
        """
        Instantiate object with the following parameters:
            host_name       ElasticSearch host name
            port_number     ElasticsSearch API port number
        """
        self.es_connection = Connection(host_name, port_number)

    def create_index(self, index_name, shards, replicas):
        """
        Create an ElasticSearch index
            index_name      Name of index to be created
            shards          Number of shards for index
            replicas        Number of replicas for index
        """
        es = self.es_connection.get_connection()
        result = es.indices.create(
            index=index_name,
            body={
                'settings': {
                    'number_of_shards': shards,
                    'number_of_replicas': replicas
                }
            },
            # Do not generate an error if index exists
            ignore=400)

        # Display error if there is one
        acknowledge_result(result)

    def delete_index(self, index_name):
        """
        Delete an ElasticSearch index
            index_name      Name of index to be deleted
        """
        es = self.es_connection.get_connection()
        result = es.indices.delete(index=index_name)

        # Display error if there is one
        acknowledge_result(result)

    def open_index(self, index_name):
        """
        Open a closed index in the ElasticSearch cluster
            index_name      Name of index to be opened
        """
        es = self.es_connection.get_connection()
        result = es.indices.open(index=index_name)

        # Display error if there is one
        acknowledge_result(result)

    def close_index(self, index_name):
        """
        Close an index on the ElasticSearch cluster
            index_name      Name of index to be closed
        """
        es = self.es_connection.get_connection()
        result = es.indices.close(index=index_name)

        # Print an error if one occurred
        acknowledge_result(result)

    def flush_index(self, index_name):
        """
        Flush all of the documents out of the target index
            index_name      Name of index to be flushed
        """
        es = self.es_connection.get_connection()
        result = es.indices.flush(index=index_name)

        # Print an error if one occurred
        acknowledge_result(result)

    def list_index(self, index_name):
        """
        Display a list of indices in the ElasticSearch cluster.
            index_name      Name of index to list (default is _all)
        """
        es = self.es_connection.get_connection()
        result = es.indices.get_settings(index=index_name)

        # Print an error if one occurred
        acknowledge_result(result)

    def show_stats(self, index_name):
        """
        Display performance metrics for specified index.
        """
        es = self.es_connection.get_connection()
        result = es.indices.stats(index_name)

        # Print an error if one occurred
        acknowledge_result(result)