fix: ES 自动创建索引

This commit is contained in:
xinwen
2021-04-13 09:18:29 +08:00
committed by 老广
parent b97759687d
commit ce6b9de07c
3 changed files with 36 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import inspect
from django.db.models import QuerySet as DJQuerySet
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
from elasticsearch.exceptions import RequestError
from common.utils.common import lazyproperty
from common.utils import get_logger
@@ -31,6 +32,15 @@ class CommandStore():
kwargs['verify_certs'] = None
self.es = Elasticsearch(hosts=hosts, max_retries=0, **kwargs)
def pre_use_check(self):
self._ensure_index_exists()
def _ensure_index_exists(self):
try:
self.es.indices.create(self.index)
except RequestError:
pass
@staticmethod
def make_data(command):
data = dict(
@@ -234,6 +244,7 @@ class QuerySet(DJQuerySet):
uqs = QuerySet(self._command_store_config)
uqs._method_calls = self._method_calls.copy()
uqs._slice = self._slice
uqs.model = self.model
return uqs
def count(self, limit_to_max_result_window=True):