Skip to content

Commit 0d7f8bf

Browse files
committed
TM: upgrade code to elasticsearch 7.x
The most notable change is how multiple mapping types are not supported in indices. As suggested by the official docs, we'll create separate indexes for each locale, and hence avoid clashes. Note how index names must be lowercase, too. This change, as well as upgrading to elasticsearch 7.x, requires servers to rebuild their indices.
1 parent d4dbd71 commit 0d7f8bf

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

docs/ref-settings.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,7 @@ ZING_TM_SERVER = {
258258

259259
The TM is automatically updated every time a new translation is submitted.
260260

261-
Optionally, a couple of details can be configured:
262-
263-
* `INDEX_NAME` (_string_) allows defining the name of the index under which the
264-
Translation Memory database will be constructed. It defaults to
265-
`translations`.
261+
Optionally, matching similarity can be configured:
266262

267263
* `MIN_SIMILARITY` (_float_) serves as a threshold value to filter out results
268264
that are potentially too far from the source text. The Levenshtein distance is

pootle/apps/pootle_app/management/commands/update_tmserver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def get_unit_data(self, unit):
8080
if unit['submitted_on']:
8181
mtime = int(dateformat.format(unit['submitted_on'], 'U'))
8282

83+
index_name = unit['store__translation_project__language__code'].lower()
8384
return {
84-
'_index': self.INDEX_NAME,
85-
'_type': unit['store__translation_project__language__code'],
85+
'_index': index_name,
8686
'_id': unit['id'],
8787
'revision': int(unit['revision']),
8888
'project': unit['store__translation_project__project__fullname'],

pootle/core/search/backends/elasticsearch.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
logger = logging.getLogger(__name__)
2929

3030

31-
DEFAULT_INDEX_NAME = 'translations'
3231
DEFAULT_MIN_SIMILARITY = 0.7
3332

3433

@@ -69,19 +68,17 @@ class ElasticSearchBackend(SearchBackend):
6968
def __init__(self):
7069
super(ElasticSearchBackend, self).__init__()
7170
self._es = self._get_es_server()
72-
self._index_name = self._settings.get('INDEX_NAME', DEFAULT_INDEX_NAME)
73-
self._create_index_if_missing()
7471

7572
def _get_es_server(self):
7673
return Elasticsearch([
7774
{'host': self._settings['HOST'],
7875
'port': self._settings['PORT']},
7976
])
8077

81-
def _create_index_if_missing(self):
78+
def _create_index_if_missing(self, name):
8279
try:
83-
if not self._es.indices.exists(self._index_name):
84-
self._es.indices.create(self._index_name)
80+
if not self._es.indices.exists(name):
81+
self._es.indices.create(name)
8582
except ElasticsearchException as e:
8683
self._log_error(e)
8784

@@ -105,8 +102,7 @@ def search(self, unit):
105102
language = unit.store.translation_project.language.code
106103
es_res = self._es_call(
107104
"search",
108-
index=self._index_name,
109-
doc_type=language,
105+
index=language,
110106
body={
111107
"query": {
112108
"match": {
@@ -163,10 +159,11 @@ def search(self, unit):
163159
return res
164160

165161
def update(self, language, obj):
162+
index_name = language.lower()
163+
self._create_index_if_missing(index_name)
166164
self._es_call(
167165
"index",
168-
index=self._index_name,
169-
doc_type=language,
166+
index=index_name,
170167
body=obj,
171168
id=obj['id']
172169
)

pootle/settings/90-local.conf.template

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ DATABASES = {
9898
#ZING_TM_SERVER = {
9999
# 'HOST': 'localhost',
100100
# 'PORT': 9200,
101-
# # Optional index name
102-
# 'INDEX_NAME': 'translations',
103101
#}
104102

105103
#

0 commit comments

Comments
 (0)