From 98a89265c08d5eb975017c5cc89c2bd177b281b6 Mon Sep 17 00:00:00 2001 From: TheAMM Date: Wed, 16 May 2018 19:53:09 +0300 Subject: [PATCH] config: Add Elasticsearch hosts --- config.example.py | 2 ++ import_to_es.py | 2 +- nyaa/search.py | 2 +- sync_es.py | 6 +++++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config.example.py b/config.example.py index 844c0e8..67d6d01 100644 --- a/config.example.py +++ b/config.example.py @@ -144,6 +144,8 @@ ENABLE_ELASTIC_SEARCH_HIGHLIGHT = False ES_MAX_SEARCH_RESULT = 1000 # ES index name generally (nyaa or sukebei) ES_INDEX_NAME = SITE_FLAVOR +# ES hosts +ES_HOSTS = ['localhost:9200'] ################ ## Commenting ## diff --git a/import_to_es.py b/import_to_es.py index c2ed46f..c244abb 100755 --- a/import_to_es.py +++ b/import_to_es.py @@ -18,7 +18,7 @@ from nyaa import create_app, models from nyaa.extensions import db app = create_app('config') -es = Elasticsearch(timeout=30) +es = Elasticsearch(hosts=app.config['ES_HOSTS'], timeout=30) ic = IndicesClient(es) def pad_bytes(in_bytes, size): diff --git a/nyaa/search.py b/nyaa/search.py index e8972a1..d1a5282 100644 --- a/nyaa/search.py +++ b/nyaa/search.py @@ -185,7 +185,7 @@ def search_elastic(term='', user=None, sort='id', order='desc', if page > 4294967295: flask.abort(404) - es_client = Elasticsearch() + es_client = Elasticsearch(hosts=app.config['ES_HOSTS']) es_sort_keys = { 'id': 'id', diff --git a/sync_es.py b/sync_es.py index c4a9025..382c744 100755 --- a/sync_es.py +++ b/sync_es.py @@ -34,7 +34,11 @@ from elasticsearch.helpers import bulk, BulkIndexError from pymysqlreplication import BinLogStreamReader from pymysqlreplication.row_event import UpdateRowsEvent, DeleteRowsEvent, WriteRowsEvent from datetime import datetime + +from nyaa import create_app, db, models from nyaa.models import TorrentFlags +app = create_app('config') + import sys import json import time @@ -262,7 +266,7 @@ class EsPoster(ExitingThread): self.flush_interval = flush_interval def run_happy(self): - es = Elasticsearch(timeout=30) + es = Elasticsearch(hosts=app.config['ES_HOSTS'], timeout=30) last_save = time.time() since_last = 0