Skip to content

Commit 3c1e3e3

Browse files
committed
configurable shards
1 parent 4a53685 commit 3c1e3e3

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

base.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ retry.attempts = 3
55
file_upload_bucket = snowflakes-files-dev
66
file_upload_profile_name = snowflakes-files-upload
77
elasticsearch.server = localhost:9201
8+
elasticsearch.shards.primary = 1
9+
elasticsearch.shards.replicate = 0
810
aws_ip_ranges_path = %(here)s/aws-ip-ranges.json
911
download_proxy = https://download.encodeproject.org/
1012
annotations_path = %(here)s/annotations.json

src/snovault/elasticsearch/create_mapping.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ def schema_mapping(name, schema):
164164
}
165165

166166

167-
def index_settings():
167+
def index_settings(primary_shards=3, replicate_shards=1):
168168
return {
169169
'settings': {
170170
'index.max_result_window': 99999,
171171
'index.mapping.total_fields.limit': 5000,
172-
'index.number_of_shards': 1,
173-
'index.number_of_replicas': 0,
172+
'index.number_of_shards': primary_shards,
173+
'index.number_of_replicas': replicate_shards,
174174
'index.max_ngram_diff': 32,
175175
'analysis': {
176176
'filter': {
@@ -484,6 +484,8 @@ def create_snovault_index_alias(es, indices):
484484
def run(app, collections=None, dry_run=False):
485485
index = app.registry.settings['snovault.elasticsearch.index']
486486
registry = app.registry
487+
primary_shards = registry.settings.get('elasticsearch.shards.primary', 3)
488+
replicate_shards = registry.settings.get('elasticsearch.shards.replicate', 1)
487489
if not dry_run:
488490
es = app.registry[ELASTIC_SEARCH]
489491
print('CREATE MAPPING RUNNING')
@@ -503,9 +505,9 @@ def run(app, collections=None, dry_run=False):
503505
if mapping is None:
504506
continue # Testing collections
505507
if dry_run:
506-
print(json.dumps(sorted_dict({index: {doc_type: mapping}}), indent=4))
508+
print(json.dumps(sorted_dict({index: {collection_name: mapping}}), indent=4))
507509
continue
508-
create_elasticsearch_index(es, index, index_settings())
510+
create_elasticsearch_index(es, index, index_settings(primary_shards, replicate_shards))
509511
set_index_mapping(es, index, mapping)
510512
if collection_name != 'meta':
511513
indices.append(index)

0 commit comments

Comments
 (0)