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.
This commit is contained in:
committed by
Jason Veatch
parent
2bc407e633
commit
5f199882d8
+61
-54
@@ -10,6 +10,7 @@ import logging
|
||||
import git
|
||||
|
||||
from elasticsearch import Elasticsearch
|
||||
from elasticsearch.exceptions import TransportError
|
||||
from elasticsearch.helpers import bulk, streaming_bulk
|
||||
|
||||
def create_git_index(client, index):
|
||||
@@ -17,69 +18,75 @@ def create_git_index(client, index):
|
||||
user_mapping = {
|
||||
'properties': {
|
||||
'name': {
|
||||
'type': 'multi_field',
|
||||
'type': 'string',
|
||||
'fields': {
|
||||
'raw': {'type' : 'string', 'index' : 'not_analyzed'},
|
||||
'name': {'type' : 'string'}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
create_index_body = {
|
||||
'settings': {
|
||||
# just one shard, no replicas for testing
|
||||
'number_of_shards': 1,
|
||||
'number_of_replicas': 0,
|
||||
|
||||
# custom analyzer for analyzing file paths
|
||||
'analysis': {
|
||||
'analyzer': {
|
||||
'file_path': {
|
||||
'type': 'custom',
|
||||
'tokenizer': 'path_hierarchy',
|
||||
'filter': ['lowercase']
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'mappings': {
|
||||
'commits': {
|
||||
'_parent': {
|
||||
'type': 'repos'
|
||||
},
|
||||
'properties': {
|
||||
'author': user_mapping,
|
||||
'authored_date': {'type': 'date'},
|
||||
'committer': user_mapping,
|
||||
'committed_date': {'type': 'date'},
|
||||
'parent_shas': {'type': 'string', 'index' : 'not_analyzed'},
|
||||
'description': {'type': 'string', 'analyzer': 'snowball'},
|
||||
'files': {'type': 'string', 'analyzer': 'file_path'}
|
||||
}
|
||||
},
|
||||
'repos': {
|
||||
'properties': {
|
||||
'owner': user_mapping,
|
||||
'created_at': {'type': 'date'},
|
||||
'description': {
|
||||
'type': 'string',
|
||||
'analyzer': 'snowball',
|
||||
},
|
||||
'tags': {
|
||||
'type': 'string',
|
||||
'index': 'not_analyzed'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# create empty index
|
||||
client.indices.create(
|
||||
index=index,
|
||||
body={
|
||||
'settings': {
|
||||
# just one shard, no replicas for testing
|
||||
'number_of_shards': 1,
|
||||
'number_of_replicas': 0,
|
||||
|
||||
# custom analyzer for analyzing file paths
|
||||
'analysis': {
|
||||
'analyzer': {
|
||||
'file_path': {
|
||||
'type': 'custom',
|
||||
'tokenizer': 'path_hierarchy',
|
||||
'filter': ['lowercase']
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'mappings': {
|
||||
'commits': {
|
||||
'_parent': {
|
||||
'type': 'repos'
|
||||
},
|
||||
'properties': {
|
||||
'author': user_mapping,
|
||||
'authored_date': {'type': 'date'},
|
||||
'committer': user_mapping,
|
||||
'committed_date': {'type': 'date'},
|
||||
'parent_shas': {'type': 'string', 'index' : 'not_analyzed'},
|
||||
'description': {'type': 'string', 'analyzer': 'snowball'},
|
||||
'files': {'type': 'string', 'analyzer': 'file_path'}
|
||||
}
|
||||
},
|
||||
'repos': {
|
||||
'properties': {
|
||||
'owner': user_mapping,
|
||||
'created_at': {'type': 'date'},
|
||||
'description': {
|
||||
'type': 'string',
|
||||
'analyzer': 'snowball',
|
||||
},
|
||||
'tags': {
|
||||
'type': 'string',
|
||||
'index': 'not_analyzed'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
try:
|
||||
client.indices.create(
|
||||
index=index,
|
||||
body=create_index_body,
|
||||
)
|
||||
except TransportError, e:
|
||||
# ignore already existing index
|
||||
ignore=400
|
||||
)
|
||||
if e.error == 'index_already_exists_exception':
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
|
||||
def parse_commits(head, name):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user