parsedmarc/elastic.py
def migrate_indexes(aggregate_indexes=None, forensic_indexes=None):
    """
    Updates index mappings

    Args:
        aggregate_indexes (list): A list of aggregate index names
        forensic_indexes (list): A list of forensic index names
    """
    version = 2
    if aggregate_indexes is None:
        aggregate_indexes = []
    if forensic_indexes is None:
        forensic_indexes = []
    for aggregate_index_name in aggregate_indexes:
        if not Index(aggregate_index_name).exists():
            continue
        aggregate_index = Index(aggregate_index_name)
        doc = "doc"
        fo_field = "published_policy.fo"
        fo = "fo"
        fo_mapping = aggregate_index.get_field_mapping(fields=[fo_field])
        fo_mapping = fo_mapping[list(fo_mapping.keys())[0]]["mappings"]
        if doc not in fo_mapping:
            continue

        fo_mapping = fo_mapping[doc][fo_field]["mapping"][fo]
        fo_type = fo_mapping["type"]
        if fo_type == "long":
            new_index_name = "{0}-v{1}".format(aggregate_index_name, version)
            body = {"properties": {"published_policy.fo": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            }
            }
            }
            Index(new_index_name).create()
            Index(new_index_name).put_mapping(doc_type=doc, body=body)
            reindex(connections.get_connection(), aggregate_index_name,
                    new_index_name)
            Index(aggregate_index_name).delete()

    for forensic_index in forensic_indexes:
        pass
def migrate_indexes(aggregate_indexes=None, forensic_indexes=None):
    version = 2
    if aggregate_indexes is None:
        aggregate_indexes = []
    if forensic_indexes is None:
        forensic_indexes = []
    for aggregate_index_name in aggregate_indexes:
        if not Index(aggregate_index_name).exists():
            continue
        aggregate_index = Index(aggregate_index_name)
        doc = "doc"
        fo_field = "published_policy.fo"
        fo = "fo"
        fo_mapping = aggregate_index.get_field_mapping(fields=[fo_field])
        fo_mapping = fo_mapping[list(fo_mapping.keys())[0]]["mappings"]
        if doc not in fo_mapping:
            continue

        fo_mapping = fo_mapping[doc][fo_field]["mapping"][fo]
        fo_type = fo_mapping["type"]
        if fo_type == "long":
            new_index_name = "{0}-v{1}".format(aggregate_index_name, version)
            body = {"properties": {"published_policy.fo": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            }
            }
            }
            Index(new_index_name).create()
            Index(new_index_name).put_mapping(doc_type=doc, body=body)
            reindex(connections.get_connection(), aggregate_index_name,
                    new_index_name)
            Index(aggregate_index_name).delete()

    for forensic_index in forensic_indexes:
        pass
def migrate_indexes ( aggregate_indexes = None , forensic_indexes = None ) : version = 2 if aggregate_indexes is None : aggregate_indexes = [ ] if forensic_indexes is None : forensic_indexes = [ ] for aggregate_index_name in aggregate_indexes : if not Index ( aggregate_index_name ) . exists ( ) : continue aggregate_index = Index ( aggregate_index_name ) doc = "doc" fo_field = "published_policy.fo" fo = "fo" fo_mapping = aggregate_index . get_field_mapping ( fields = [ fo_field ] ) fo_mapping = fo_mapping [ list ( fo_mapping . keys ( ) ) [ 0 ] ] [ "mappings" ] if doc not in fo_mapping : continue fo_mapping = fo_mapping [ doc ] [ fo_field ] [ "mapping" ] [ fo ] fo_type = fo_mapping [ "type" ] if fo_type == "long" : new_index_name = "{0}-v{1}" . format ( aggregate_index_name , version ) body = { "properties" : { "published_policy.fo" : { "type" : "text" , "fields" : { "keyword" : { "type" : "keyword" , "ignore_above" : 256 } } } } } Index ( new_index_name ) . create ( ) Index ( new_index_name ) . put_mapping ( doc_type = doc , body = body ) reindex ( connections . get_connection ( ) , aggregate_index_name , new_index_name ) Index ( aggregate_index_name ) . delete ( ) for forensic_index in forensic_indexes : pass
Updates index mappings

    Args:
        aggregate_indexes (list): A list of aggregate index names
        forensic_indexes (list): A list of forensic index names
Updates index mappings