Skip to content

Commit 5f19988

Browse files
veatchJason Veatch
authored andcommitted
multi_field type is removed from 5, move to new format
Instead of ignoring all 400s when creating the index, only ignore index_already_exists_exception and raise other exceptions.
1 parent 2bc407e commit 5f19988

File tree

1 file changed

+57
-50
lines changed

1 file changed

+57
-50
lines changed

example/load.py

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,83 @@
1010
import git
1111

1212
from elasticsearch import Elasticsearch
13+
from elasticsearch.exceptions import TransportError
1314
from elasticsearch.helpers import bulk, streaming_bulk
1415

1516
def create_git_index(client, index):
1617
# we will use user on several places
1718
user_mapping = {
1819
'properties': {
1920
'name': {
20-
'type': 'multi_field',
21+
'type': 'string',
2122
'fields': {
2223
'raw': {'type' : 'string', 'index' : 'not_analyzed'},
23-
'name': {'type' : 'string'}
2424
}
2525
}
2626
}
2727
}
2828

29-
# create empty index
30-
client.indices.create(
31-
index=index,
32-
body={
33-
'settings': {
34-
# just one shard, no replicas for testing
35-
'number_of_shards': 1,
36-
'number_of_replicas': 0,
37-
38-
# custom analyzer for analyzing file paths
39-
'analysis': {
40-
'analyzer': {
41-
'file_path': {
42-
'type': 'custom',
43-
'tokenizer': 'path_hierarchy',
44-
'filter': ['lowercase']
45-
}
46-
}
29+
create_index_body = {
30+
'settings': {
31+
# just one shard, no replicas for testing
32+
'number_of_shards': 1,
33+
'number_of_replicas': 0,
34+
35+
# custom analyzer for analyzing file paths
36+
'analysis': {
37+
'analyzer': {
38+
'file_path': {
39+
'type': 'custom',
40+
'tokenizer': 'path_hierarchy',
41+
'filter': ['lowercase']
4742
}
43+
}
44+
}
45+
},
46+
'mappings': {
47+
'commits': {
48+
'_parent': {
49+
'type': 'repos'
4850
},
49-
'mappings': {
50-
'commits': {
51-
'_parent': {
52-
'type': 'repos'
53-
},
54-
'properties': {
55-
'author': user_mapping,
56-
'authored_date': {'type': 'date'},
57-
'committer': user_mapping,
58-
'committed_date': {'type': 'date'},
59-
'parent_shas': {'type': 'string', 'index' : 'not_analyzed'},
60-
'description': {'type': 'string', 'analyzer': 'snowball'},
61-
'files': {'type': 'string', 'analyzer': 'file_path'}
62-
}
51+
'properties': {
52+
'author': user_mapping,
53+
'authored_date': {'type': 'date'},
54+
'committer': user_mapping,
55+
'committed_date': {'type': 'date'},
56+
'parent_shas': {'type': 'string', 'index' : 'not_analyzed'},
57+
'description': {'type': 'string', 'analyzer': 'snowball'},
58+
'files': {'type': 'string', 'analyzer': 'file_path'}
59+
}
60+
},
61+
'repos': {
62+
'properties': {
63+
'owner': user_mapping,
64+
'created_at': {'type': 'date'},
65+
'description': {
66+
'type': 'string',
67+
'analyzer': 'snowball',
6368
},
64-
'repos': {
65-
'properties': {
66-
'owner': user_mapping,
67-
'created_at': {'type': 'date'},
68-
'description': {
69-
'type': 'string',
70-
'analyzer': 'snowball',
71-
},
72-
'tags': {
73-
'type': 'string',
74-
'index': 'not_analyzed'
75-
}
76-
}
69+
'tags': {
70+
'type': 'string',
71+
'index': 'not_analyzed'
7772
}
7873
}
79-
},
74+
}
75+
}
76+
}
77+
78+
# create empty index
79+
try:
80+
client.indices.create(
81+
index=index,
82+
body=create_index_body,
83+
)
84+
except TransportError, e:
8085
# ignore already existing index
81-
ignore=400
82-
)
86+
if e.error == 'index_already_exists_exception':
87+
pass
88+
else:
89+
raise
8390

8491
def parse_commits(head, name):
8592
"""

0 commit comments

Comments
 (0)