|
19 | 19 |
|
20 | 20 | from elasticsearch import Elasticsearch |
21 | 21 |
|
| 22 | +user_mapping = { |
| 23 | + "properties": {"name": {"type": "text", "fields": {"raw": {"type": "keyword"}}}} |
| 24 | +} |
22 | 25 |
|
23 | | -def create_flat_git_index(client: Elasticsearch, index: str) -> None: |
24 | | - # we will use user on several places |
25 | | - user_mapping = { |
26 | | - "properties": {"name": {"type": "text", "fields": {"raw": {"type": "keyword"}}}} |
27 | | - } |
28 | | - |
29 | | - client.indices.create( |
30 | | - index=index, |
31 | | - body={ |
32 | | - "settings": { |
33 | | - # just one shard, no replicas for testing |
34 | | - "number_of_shards": 1, |
35 | | - "number_of_replicas": 0, |
36 | | - # custom analyzer for analyzing file paths |
37 | | - "analysis": { |
38 | | - "analyzer": { |
39 | | - "file_path": { |
40 | | - "type": "custom", |
41 | | - "tokenizer": "path_hierarchy", |
42 | | - "filter": ["lowercase"], |
43 | | - } |
44 | | - } |
45 | | - }, |
46 | | - }, |
47 | | - "mappings": { |
48 | | - "properties": { |
49 | | - "description": {"type": "text", "analyzer": "snowball"}, |
50 | | - "author": user_mapping, |
51 | | - "authored_date": {"type": "date"}, |
52 | | - "committer": user_mapping, |
53 | | - "committed_date": {"type": "date"}, |
54 | | - "parent_shas": {"type": "keyword"}, |
55 | | - "files": { |
56 | | - "type": "text", |
57 | | - "analyzer": "file_path", |
58 | | - "fielddata": True, |
59 | | - }, |
| 26 | +FLAT_GIT_INDEX: Dict[str, Any] = { |
| 27 | + "settings": { |
| 28 | + # just one shard, no replicas for testing |
| 29 | + "number_of_shards": 1, |
| 30 | + "number_of_replicas": 0, |
| 31 | + # custom analyzer for analyzing file paths |
| 32 | + "analysis": { |
| 33 | + "analyzer": { |
| 34 | + "file_path": { |
| 35 | + "type": "custom", |
| 36 | + "tokenizer": "path_hierarchy", |
| 37 | + "filter": ["lowercase"], |
60 | 38 | } |
| 39 | + } |
| 40 | + }, |
| 41 | + }, |
| 42 | + "mappings": { |
| 43 | + "properties": { |
| 44 | + "description": {"type": "text", "analyzer": "snowball"}, |
| 45 | + "author": user_mapping, |
| 46 | + "authored_date": {"type": "date"}, |
| 47 | + "committer": user_mapping, |
| 48 | + "committed_date": {"type": "date"}, |
| 49 | + "parent_shas": {"type": "keyword"}, |
| 50 | + "files": { |
| 51 | + "type": "text", |
| 52 | + "analyzer": "file_path", |
| 53 | + "fielddata": True, |
61 | 54 | }, |
| 55 | + } |
| 56 | + }, |
| 57 | +} |
| 58 | + |
| 59 | +GIT_INDEX: Dict[str, Any] = { |
| 60 | + "settings": { |
| 61 | + # just one shard, no replicas for testing |
| 62 | + "number_of_shards": 1, |
| 63 | + "number_of_replicas": 0, |
| 64 | + # custom analyzer for analyzing file paths |
| 65 | + "analysis": { |
| 66 | + "analyzer": { |
| 67 | + "file_path": { |
| 68 | + "type": "custom", |
| 69 | + "tokenizer": "path_hierarchy", |
| 70 | + "filter": ["lowercase"], |
| 71 | + } |
| 72 | + } |
62 | 73 | }, |
63 | | - ) |
| 74 | + }, |
| 75 | + "mappings": { |
| 76 | + "properties": { |
| 77 | + # common fields |
| 78 | + "description": {"type": "text", "analyzer": "snowball"}, |
| 79 | + "commit_repo": {"type": "join", "relations": {"repo": "commit"}}, |
| 80 | + # COMMIT mappings |
| 81 | + "author": user_mapping, |
| 82 | + "authored_date": {"type": "date"}, |
| 83 | + "committer": user_mapping, |
| 84 | + "committed_date": {"type": "date"}, |
| 85 | + "parent_shas": {"type": "keyword"}, |
| 86 | + "files": { |
| 87 | + "type": "text", |
| 88 | + "analyzer": "file_path", |
| 89 | + "fielddata": True, |
| 90 | + }, |
| 91 | + # REPO mappings |
| 92 | + "is_public": {"type": "boolean"}, |
| 93 | + "owner": user_mapping, |
| 94 | + "created_at": {"type": "date"}, |
| 95 | + "tags": {"type": "keyword"}, |
| 96 | + } |
| 97 | + }, |
| 98 | +} |
64 | 99 |
|
65 | 100 |
|
66 | | -def create_git_index(client: Elasticsearch, index: str) -> None: |
67 | | - # we will use user on several places |
68 | | - user_mapping = { |
69 | | - "properties": {"name": {"type": "text", "fields": {"raw": {"type": "keyword"}}}} |
70 | | - } |
| 101 | +def create_flat_git_index(client: Elasticsearch, index: str) -> None: |
| 102 | + client.indices.create(index=index, body=FLAT_GIT_INDEX) |
71 | 103 |
|
72 | | - client.indices.create( |
73 | | - index=index, |
74 | | - body={ |
75 | | - "settings": { |
76 | | - # just one shard, no replicas for testing |
77 | | - "number_of_shards": 1, |
78 | | - "number_of_replicas": 0, |
79 | | - # custom analyzer for analyzing file paths |
80 | | - "analysis": { |
81 | | - "analyzer": { |
82 | | - "file_path": { |
83 | | - "type": "custom", |
84 | | - "tokenizer": "path_hierarchy", |
85 | | - "filter": ["lowercase"], |
86 | | - } |
87 | | - } |
88 | | - }, |
89 | | - }, |
90 | | - "mappings": { |
91 | | - "properties": { |
92 | | - # common fields |
93 | | - "description": {"type": "text", "analyzer": "snowball"}, |
94 | | - "commit_repo": {"type": "join", "relations": {"repo": "commit"}}, |
95 | | - # COMMIT mappings |
96 | | - "author": user_mapping, |
97 | | - "authored_date": {"type": "date"}, |
98 | | - "committer": user_mapping, |
99 | | - "committed_date": {"type": "date"}, |
100 | | - "parent_shas": {"type": "keyword"}, |
101 | | - "files": { |
102 | | - "type": "text", |
103 | | - "analyzer": "file_path", |
104 | | - "fielddata": True, |
105 | | - }, |
106 | | - # REPO mappings |
107 | | - "is_public": {"type": "boolean"}, |
108 | | - "owner": user_mapping, |
109 | | - "created_at": {"type": "date"}, |
110 | | - "tags": {"type": "keyword"}, |
111 | | - } |
112 | | - }, |
113 | | - }, |
114 | | - ) |
| 104 | + |
| 105 | +def create_git_index(client: Elasticsearch, index: str) -> None: |
| 106 | + client.indices.create(index=index, body=GIT_INDEX) |
115 | 107 |
|
116 | 108 |
|
117 | 109 | DATA = [ |
|
0 commit comments