Beispiel #1
0
def show_index(endpoint, regex):
    es = Elasticsearch(endpoint)
    try:
        indices = []
        for index in es.indices.stats()["indices"]:
            try:
                if re.match(regex, index):
                    indices.append(index)
            except re.error as e:
                return APIMessage("ERROR", "Bad regular expression {0} ({1})".format(regex, e))
        if len(indices):
            indices.sort()
            result = APIMessage("OK", "Found {0} indices".format(len(indices)))
            for index in indices:
                sub_rows = []
                settings = es.indices.get_settings(index)
                stats = es.indices.stats(index)
                sub_rows.append(APIMessageRow("number_of_shards",settings[index]["settings"]["index"]["number_of_shards"]))
                sub_rows.append(APIMessageRow("number_of_replicas",settings[index]["settings"]["index"]["number_of_replicas"]))
                sub_rows.append(APIMessageRow("document_count",stats["_all"]["total"]["docs"]["count"]))
                sub_rows.append(APIMessageRow("segment_count",stats["_all"]["total"]["segments"]["count"]))
                result.add_row(APIMessageRow(index, sub_rows))
            return result
        else:
            return APIMessage("ERROR", "No index found")
    except ConnectionError as e:
        return APIMessage("ERROR", e)
Beispiel #2
0
def list_index(endpoint, regex):
    es = Elasticsearch(endpoint)
    try:
        indices = []
        for index in es.indices.stats()["indices"]:
            try:
                if re.match(regex, index):
                    indices.append(index)
            except re.error as e:
                return APIMessage("ERROR", "Bad regular expression {0} ({1})".format(regex, e))
        if len(indices):
            indices.sort()
            result = APIMessage("OK", "Found {0} indices".format(len(indices)))
            for index in indices:
                result.add_row(APIMessageRow(index))
            return result
        else:
            return APIMessage("ERROR", "No index found")
    except ConnectionError as e:
        return APIMessage("ERROR", e)