Skip to content

Commit f221f97

Browse files
authored
Merge pull request #4909 from safwanrahman/search_fix
Tuning Elasticsearch for search improvements
2 parents 57c7b57 + 7bea6d8 commit f221f97

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

readthedocs/search/documents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Meta(object):
5959
title = fields.TextField(attr='processed_json.title')
6060
headers = fields.TextField(attr='processed_json.headers')
6161
content = fields.TextField(attr='processed_json.content')
62-
path = fields.TextField(attr='processed_json.path')
62+
path = fields.KeywordField(attr='processed_json.path')
6363

6464
# Fields to perform search with weight
6565
search_fields = ['title^10', 'headers^5', 'content']

readthedocs/settings/base.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,29 @@ def USE_PROMOS(self): # noqa
343343
ES_INDEXES = {
344344
'project': {
345345
'name': 'project_index',
346-
'settings': {'number_of_shards': 5,
346+
# We do not have much data in the project index, therefore only 1 shard with
347+
# 1 replica is appropriate project index
348+
'settings': {'number_of_shards': 1,
347349
'number_of_replicas': 1
348350
}
349351
},
350352
'page': {
351353
'name': 'page_index',
352354
'settings': {
353-
'number_of_shards': 5,
354-
'number_of_replicas': 1,
355+
# We have 3 nodes, therefore having 3 shards and each one having 3 replica
356+
# will be good fit for our infrastructure. So all the 9(3*3) shards will be
357+
# allocated to 3 nodes. Therefore, if one nodes get failed, the data will be
358+
# inside other nodes and Elasticsearch can serve properly.
359+
'number_of_shards': 3,
360+
'number_of_replicas': 3,
361+
"index": {
362+
"sort.field": ["project", "version"]
363+
}
355364
}
356365
},
357366
}
367+
# Disable auto refresh for increasing index performance
368+
ELASTICSEARCH_DSL_AUTO_REFRESH = False
358369

359370
ALLOWED_HOSTS = ['*']
360371

readthedocs/settings/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CommunityTestSettings(CommunityDevSettings):
1818
TEMPLATE_DEBUG = False
1919
ES_PAGE_IGNORE_SIGNALS = False
2020
ELASTICSEARCH_DSL_AUTOSYNC = False
21+
ELASTICSEARCH_DSL_AUTO_REFRESH = True
2122

2223
@property
2324
def ES_INDEXES(self): # noqa - avoid pep8 N802

0 commit comments

Comments
 (0)