def test_get_models_no_descriptions(no_descriptions_mappings): """ Test that default behavior without descriptions is preserved """ root, expected = no_descriptions_mappings mappings = get_es_models(str(root)) for name, mapping in mappings.items(): assert expected[name]['mapping'] == mapping[name]['_mapping']
def test_get_models_empty_descriptions(empty_descriptions_mappings): """ Test that empty _meta descriptions are picked up as expected """ root, expected = empty_descriptions_mappings mappings = get_es_models(str(root)) for name, mapping in mappings.items(): assert expected[name]['mapping'] == mapping[name]['_mapping']
def test_get_models_with_descriptions(descriptions_mappings): """ Test that descriptions are being loaded as expected """ root, expected = descriptions_mappings mappings = get_es_models(str(root)) for name, mapping in mappings.items(): assert expected[name]['mapping'] == mapping[name]['_mapping']
def test_get_models_descriptions_with_other_data( non_meta_descriptions_mappings): """ Test that non _meta descriptions are not being picked up """ root, expected = non_meta_descriptions_mappings mappings = get_es_models(str(root)) for name, mapping in mappings.items(): assert expected[name]['mapping'] == mapping[name]['_mapping']
def test_get_es_models_from_directory(foo_bar_mappings): """ Test that content of mappings and settings is correct """ root, expected = foo_bar_mappings mappings = get_es_models(str(root)) assert set(mappings.keys()) == set(expected.keys()) for name in mappings: assert expected[name]['settings'] == mappings[name]['_settings'] assert expected[name]['mapping'] == mappings[name][name]['_mapping']
def test_get_es_models_parametrized(mock_listdir): """ Test that correct mappings are created """ _, expected = mock_listdir models = get_es_models() expected_indices = set(expected.keys()) assert set(models.keys()) == expected_indices assert all(set(models[ind].keys()) == expected[ind] for ind in models)
def test_get_es_models_standard_behavior(): """ Test that correct number of index mappings are loaded """ models = get_es_models() assert len(models) == 13 for dtype in ['case', 'project', 'file', 'annotation']: dtype_mapping = models['gdc_from_graph'][dtype]['_mapping'] assert '_meta' in dtype_mapping, dtype_mapping.keys() assert 'descriptions' in dtype_mapping['_meta'] # The description field below is somewhat random, but something that # will most likely preserve during dictionary updates, if this is not # the case at some point, update it assert 'cases.case.project_id' in dtype_mapping['_meta'][ 'descriptions']
def init_index(args): es_models = get_es_models() es = get_elasticsearch(args) for index in args.index: if not es_models.get(index): print("Specified index '{}' is not defined in es-models," " skipping it!".format(index)) continue for index_type in es_models[index]: if index_type == "_settings": continue # settings, not index type full_index_name = format_index_name( prefix=args.prefix, index=index, index_type=index_type, ) if es.indices.exists(index=full_index_name): if not args.delete: print("Elasticsearch index '{}' exists, " "'--delete' not specified, skipping".format( full_index_name)) continue else: print("Elasticsearch index '{}' exists, " "'--delete' specified".format(full_index_name)) if confirm_delete(full_index_name): print("Deleting existing index '{}'".format( full_index_name)) es.indices.delete(index=full_index_name) else: print("Index name mismatch, skipping deleting") continue print("Creating index '{}'".format(full_index_name)) body = { "settings": es_models[index]["_settings"], "mappings": es_models[index][index_type]["_mapping"], } es.indices.create(index=full_index_name, body=body)
def init_index(args): es_models = get_es_models() es = Elasticsearch(hosts="%s:%s" % (args.host, args.port), http_auth=(args.user, args.password), timeout=60) for i in args.index: if not es_models.get(i): print("Specified index name '%s' is not defined in es-models, skipping it!" % i) continue index_name = '_'.join([args.prefix, i]) if es.indices.exists(index=index_name): if not args.delete: print("Elasticsearch index '%s' exists, '--delete' not specified, skipping" % index_name) continue else: print("Elasticsearch index '%s' exists, '--delete' specified" % index_name) ans = input("Confirm deleting existing index by typing the index name: ") if ans == index_name: print("Deleting existing index '%s'" % index_name) es.indices.delete(index=index_name) else: print("Index name mismatch, skipping deleting") continue print("Creating index '%s'" % index_name) es.indices.create(index=index_name, body=es_models[i]['_settings']) for index_type in es_models[i]: if index_type == '_settings': continue # settings, not index type print("Creating index mapping '%s'" % index_name) es.indices.put_mapping(doc_type=index_type, index=index_name, body=es_models[i][index_type]['_mapping'])