Skip to content

Commit 8ab66b9

Browse files
committed
update example directory to work with Es 7
1 parent c4f0454 commit 8ab66b9

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

example/load.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,15 @@ def create_git_index(client, index):
4040
},
4141
},
4242
"mappings": {
43-
"doc": {
44-
"properties": {
45-
"repository": {"type": "keyword"},
46-
"author": user_mapping,
47-
"authored_date": {"type": "date"},
48-
"committer": user_mapping,
49-
"committed_date": {"type": "date"},
50-
"parent_shas": {"type": "keyword"},
51-
"description": {"type": "text", "analyzer": "snowball"},
52-
"files": {
53-
"type": "text",
54-
"analyzer": "file_path",
55-
"fielddata": True,
56-
},
57-
}
43+
"properties": {
44+
"repository": {"type": "keyword"},
45+
"author": user_mapping,
46+
"authored_date": {"type": "date"},
47+
"committer": user_mapping,
48+
"committed_date": {"type": "date"},
49+
"parent_shas": {"type": "keyword"},
50+
"description": {"type": "text", "analyzer": "snowball"},
51+
"files": {"type": "text", "analyzer": "file_path", "fielddata": True},
5852
}
5953
},
6054
}
@@ -64,7 +58,7 @@ def create_git_index(client, index):
6458
client.indices.create(index=index, body=create_index_body)
6559
except TransportError as e:
6660
# ignore already existing index
67-
if e.error == "index_already_exists_exception":
61+
if e.error == "resource_already_exists_exception":
6862
pass
6963
else:
7064
raise
@@ -112,7 +106,6 @@ def load_repo(client, path=None, index="git"):
112106
client,
113107
parse_commits(repo.refs.master.commit, repo_name),
114108
index=index,
115-
doc_type="doc",
116109
chunk_size=50, # keep the batch sizes small for appearances only
117110
):
118111
action, result = result.popitem()
@@ -128,13 +121,13 @@ def load_repo(client, path=None, index="git"):
128121
# we manually update some documents to add additional information
129122
UPDATES = [
130123
{
131-
"_type": "doc",
124+
"_type": "_doc",
132125
"_id": "20fbba1230cabbc0f4644f917c6c2be52b8a63e8",
133126
"_op_type": "update",
134127
"doc": {"initial_commit": True},
135128
},
136129
{
137-
"_type": "doc",
130+
"_type": "_doc",
138131
"_id": "ae0073c8ca7e24d237ffd56fba495ed409081bf4",
139132
"_op_type": "update",
140133
"doc": {"release": "5.0.0"},
@@ -179,9 +172,7 @@ def load_repo(client, path=None, index="git"):
179172
es.indices.refresh(index="git")
180173

181174
# now we can retrieve the documents
182-
initial_commit = es.get(
183-
index="git", doc_type="doc", id="20fbba1230cabbc0f4644f917c6c2be52b8a63e8"
184-
)
175+
initial_commit = es.get(index="git", id="20fbba1230cabbc0f4644f917c6c2be52b8a63e8")
185176
print(
186177
"%s: %s" % (initial_commit["_id"], initial_commit["_source"]["committed_date"])
187178
)

example/queries.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
def print_search_stats(results):
1111
print("=" * 80)
12-
print("Total %d found in %dms" % (results["hits"]["total"], results["took"]))
12+
print(
13+
"Total %d found in %dms" % (results["hits"]["total"]["value"], results["took"])
14+
)
1315
print("-" * 80)
1416

1517

@@ -49,7 +51,6 @@ def print_hits(results):
4951
print('Find commits that says "fix" without touching tests:')
5052
result = es.search(
5153
index="git",
52-
doc_type="doc",
5354
body={
5455
"query": {
5556
"bool": {
@@ -64,7 +65,6 @@ def print_hits(results):
6465
print("Last 8 Commits for elasticsearch-py:")
6566
result = es.search(
6667
index="git",
67-
doc_type="doc",
6868
body={
6969
"query": {"term": {"repository": "elasticsearch-py"}},
7070
"sort": [{"committed_date": {"order": "desc"}}],
@@ -76,7 +76,6 @@ def print_hits(results):
7676
print("Stats for top 10 committers:")
7777
result = es.search(
7878
index="git",
79-
doc_type="doc",
8079
body={
8180
"size": 0,
8281
"aggs": {

0 commit comments

Comments
 (0)