<commit_before>def get_array_members(array):
    for m in array:
        if type(m) != dict:
            return array
        else:
            field = m.keys()[0]
            print field
            return get_array_members(m]field])

example_array = [{'UnitText1.En': {'$nin': [None, '']}}, {'UnitText1.He': {'$nin': [None, '']}}]

<commit_msg>Filter DSL from python - WIP<commit_after>import elasticsearch
import pprint

def get_array_members(array):
    for m in array:
        if type(m) != dict:
            return array
        else:
            field = m.keys()[0]
            print field
            return get_array_members(m[field])

example_array = [{'UnitText1.En': {'$nin': [None, '']}}, {'UnitText1.He': {'$nin': [None, '']}}]

es = elasticsearch.Elasticsearch('localhost')

search_string = '<NAME>'

es_query_filter =  {
                    'or': {
                        'filters': [
                            {
                                'and': {
                                    'filters': [
                                        {'not':
                                            {'filter':
                                                {'term':
                                                    {'UnitText1.En': None}
                                                }
                                            }
                                        },
                                        {'not':
                                            {'filter':
                                                {'term':
                                                    {'UnitText1.En': ''}
                                                }
                                            }
                                        }
                                    ]
                                }
                            },
                            {
                                'and': {
                                    'filters': [
                                        {'not':
                                            {'filter':
                                                {'term':
                                                    {'UnitText1.He': None}
                                                }
                                            }
                                        },
                                        {'not':
                                            {'filter':
                                                {'term':
                                                    {'UnitText1.He': ''}
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }

simple_filter = {
                'not': {
                    'term': {
                        'UnitText1.En': None
                    }
                }
            }

es_filtered_query = {
    'query': {
        'filtered' : {
            'query' : {
                'match' : { '_all' : search_string }
            },
            'filter': es_query_filter
        }
    }
}

es_filtered_query = {
    'query': {
        'filtered' : {
            'query' : {
                'match' : { '_all' : search_string }
            },
            #'filter': es_query_filter
            'filter': simple_filter
        }
    }
}
try:
    res = es.search(body=es_filtered_query)
    pprint.pprint(res)
except elasticsearch.exceptions.RequestError as e:
    print dir(e)
    pprint.pprint(e.info['error'])
{'fraction_non_alphanumeric': 0.09851551956815115, 'fraction_numerical': 0.002968960863697706, 'mean_word_length': 0.5358474927476171, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 52, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '793412', 'n_tokens_mistral': 736, 'n_tokens_neox': 711, 'n_words': 123}