update example directory to work with Es 7
This commit is contained in:
+13
-22
@@ -40,21 +40,15 @@ def create_git_index(client, index):
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"mappings": {
|
"mappings": {
|
||||||
"doc": {
|
"properties": {
|
||||||
"properties": {
|
"repository": {"type": "keyword"},
|
||||||
"repository": {"type": "keyword"},
|
"author": user_mapping,
|
||||||
"author": user_mapping,
|
"authored_date": {"type": "date"},
|
||||||
"authored_date": {"type": "date"},
|
"committer": user_mapping,
|
||||||
"committer": user_mapping,
|
"committed_date": {"type": "date"},
|
||||||
"committed_date": {"type": "date"},
|
"parent_shas": {"type": "keyword"},
|
||||||
"parent_shas": {"type": "keyword"},
|
"description": {"type": "text", "analyzer": "snowball"},
|
||||||
"description": {"type": "text", "analyzer": "snowball"},
|
"files": {"type": "text", "analyzer": "file_path", "fielddata": True},
|
||||||
"files": {
|
|
||||||
"type": "text",
|
|
||||||
"analyzer": "file_path",
|
|
||||||
"fielddata": True,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -64,7 +58,7 @@ def create_git_index(client, index):
|
|||||||
client.indices.create(index=index, body=create_index_body)
|
client.indices.create(index=index, body=create_index_body)
|
||||||
except TransportError as e:
|
except TransportError as e:
|
||||||
# ignore already existing index
|
# ignore already existing index
|
||||||
if e.error == "index_already_exists_exception":
|
if e.error == "resource_already_exists_exception":
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
@@ -112,7 +106,6 @@ def load_repo(client, path=None, index="git"):
|
|||||||
client,
|
client,
|
||||||
parse_commits(repo.refs.master.commit, repo_name),
|
parse_commits(repo.refs.master.commit, repo_name),
|
||||||
index=index,
|
index=index,
|
||||||
doc_type="doc",
|
|
||||||
chunk_size=50, # keep the batch sizes small for appearances only
|
chunk_size=50, # keep the batch sizes small for appearances only
|
||||||
):
|
):
|
||||||
action, result = result.popitem()
|
action, result = result.popitem()
|
||||||
@@ -128,13 +121,13 @@ def load_repo(client, path=None, index="git"):
|
|||||||
# we manually update some documents to add additional information
|
# we manually update some documents to add additional information
|
||||||
UPDATES = [
|
UPDATES = [
|
||||||
{
|
{
|
||||||
"_type": "doc",
|
"_type": "_doc",
|
||||||
"_id": "20fbba1230cabbc0f4644f917c6c2be52b8a63e8",
|
"_id": "20fbba1230cabbc0f4644f917c6c2be52b8a63e8",
|
||||||
"_op_type": "update",
|
"_op_type": "update",
|
||||||
"doc": {"initial_commit": True},
|
"doc": {"initial_commit": True},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_type": "doc",
|
"_type": "_doc",
|
||||||
"_id": "ae0073c8ca7e24d237ffd56fba495ed409081bf4",
|
"_id": "ae0073c8ca7e24d237ffd56fba495ed409081bf4",
|
||||||
"_op_type": "update",
|
"_op_type": "update",
|
||||||
"doc": {"release": "5.0.0"},
|
"doc": {"release": "5.0.0"},
|
||||||
@@ -179,9 +172,7 @@ if __name__ == "__main__":
|
|||||||
es.indices.refresh(index="git")
|
es.indices.refresh(index="git")
|
||||||
|
|
||||||
# now we can retrieve the documents
|
# now we can retrieve the documents
|
||||||
initial_commit = es.get(
|
initial_commit = es.get(index="git", id="20fbba1230cabbc0f4644f917c6c2be52b8a63e8")
|
||||||
index="git", doc_type="doc", id="20fbba1230cabbc0f4644f917c6c2be52b8a63e8"
|
|
||||||
)
|
|
||||||
print(
|
print(
|
||||||
"%s: %s" % (initial_commit["_id"], initial_commit["_source"]["committed_date"])
|
"%s: %s" % (initial_commit["_id"], initial_commit["_source"]["committed_date"])
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-4
@@ -9,7 +9,9 @@ from elasticsearch import Elasticsearch
|
|||||||
|
|
||||||
def print_search_stats(results):
|
def print_search_stats(results):
|
||||||
print("=" * 80)
|
print("=" * 80)
|
||||||
print("Total %d found in %dms" % (results["hits"]["total"], results["took"]))
|
print(
|
||||||
|
"Total %d found in %dms" % (results["hits"]["total"]["value"], results["took"])
|
||||||
|
)
|
||||||
print("-" * 80)
|
print("-" * 80)
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +51,6 @@ print_hits(es.search(index="git"))
|
|||||||
print('Find commits that says "fix" without touching tests:')
|
print('Find commits that says "fix" without touching tests:')
|
||||||
result = es.search(
|
result = es.search(
|
||||||
index="git",
|
index="git",
|
||||||
doc_type="doc",
|
|
||||||
body={
|
body={
|
||||||
"query": {
|
"query": {
|
||||||
"bool": {
|
"bool": {
|
||||||
@@ -64,7 +65,6 @@ print_hits(result)
|
|||||||
print("Last 8 Commits for elasticsearch-py:")
|
print("Last 8 Commits for elasticsearch-py:")
|
||||||
result = es.search(
|
result = es.search(
|
||||||
index="git",
|
index="git",
|
||||||
doc_type="doc",
|
|
||||||
body={
|
body={
|
||||||
"query": {"term": {"repository": "elasticsearch-py"}},
|
"query": {"term": {"repository": "elasticsearch-py"}},
|
||||||
"sort": [{"committed_date": {"order": "desc"}}],
|
"sort": [{"committed_date": {"order": "desc"}}],
|
||||||
@@ -76,7 +76,6 @@ print_hits(result)
|
|||||||
print("Stats for top 10 committers:")
|
print("Stats for top 10 committers:")
|
||||||
result = es.search(
|
result = es.search(
|
||||||
index="git",
|
index="git",
|
||||||
doc_type="doc",
|
|
||||||
body={
|
body={
|
||||||
"size": 0,
|
"size": 0,
|
||||||
"aggs": {
|
"aggs": {
|
||||||
|
|||||||
Reference in New Issue
Block a user