Skip to content

Commit

Permalink
Combine create_index and put_mapping calls for test data
Browse files Browse the repository at this point in the history
  • Loading branch information
honzakral committed Jun 10, 2015
1 parent d677bd7 commit fbde4d1
Showing 1 changed file with 41 additions and 55 deletions.
96 changes: 41 additions & 55 deletions test_elasticsearch_dsl/test_integration/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

# FIXME: copy-pasted from elasticsearch-py/example/load.py
def create_git_index(client, index):
# create empty index
# we will use user on several places
user_mapping = {
'properties': {
'name': {
'type': 'string',
'fields': {
'raw': {'type' : 'string', 'index' : 'not_analyzed'},
}
}
}
}

client.indices.create(
index=index,
body={
Expand All @@ -21,67 +32,42 @@ def create_git_index(client, index):
}
}
}
}
},
# ignore already existing index
ignore=400
)

# we will use user on several places
user_mapping = {
'properties': {
'name': {
'type': 'string',
'fields': {
'raw': {'type' : 'string', 'index' : 'not_analyzed'},
}
}
}
}

client.indices.put_mapping(
index=index,
doc_type='repos',
body={
'repos': {
'properties': {
'owner': user_mapping,
'created_at': {'type': 'date'},
'description': {
'type': 'string',
'analyzer': 'snowball',
},
'mappings': {
'commits': {
'_parent': {
'type': 'repos'
},
'tags': {
'type': 'string',
'index': 'not_analyzed'
'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'}
}
}
}
}
)

client.indices.put_mapping(
index=index,
doc_type='commits',
body={
'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'
}
}
}
}
}
},
# ignore already existing index
ignore=400
)


DATA = [
# repository
{'_type': 'repos', '_id': 'elasticsearch-dsl-py', '_source': {'organization': 'elasticsearch', 'created_at': '2014-03-03', 'owner': {'name': 'elasticsearch'}}, '_index': 'git'},
Expand Down

0 comments on commit fbde4d1

Please sign in to comment.