Commit e7ac9456 authored by Alessandro CERIONI's avatar Alessandro CERIONI
Browse files

Generating index aliases for posts having status = publish, draft, private.

parent ea2fc2af
from elasticsearch import Elasticsearch
import json
def alias_setter(cfg):
es = Elasticsearch( [cfg['reindexer']['destination_url']] )
suffixes = ['publish', 'draft', 'private']
successful = True
for suffix in suffixes:
alias = "%s.%s" % (cfg['reindexer']['destination_index'], suffix)
the_body = { "filter" : {
"terms" : {
"status.keyword" : [suffix]
}
}
}
#print(the_body)
res = es.indices.put_alias(index=cfg['reindexer']['destination_index'],
name=alias,
body=json.dumps(the_body))
#print(res)
successful *= res['acknowledged']
#print(successful)
return successful
......@@ -4,6 +4,7 @@ from lib.content_getter import get_posts_by_page
from lib.content_processor import process_posts
from lib.indexer import index_docs
from lib.reindexer import reindexer
from lib.alias_setter import alias_setter
def main():
......@@ -47,6 +48,13 @@ def main():
task_url = reindexer(cfg)
#print(task_url)
print('Setting aliases...')
successful = alias_setter(cfg)
if not successful:
print('Something went wrong. Exiting...')
exit(1)
print('done.')
return task_url
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment