asticsearch: NotFoundError - PullRequest
2 голосов
/ 04 ноября 2019

Установлено elasticsearch. Я пытаюсь найти записи, но когда я пытаюсь выполнить итерацию, я получаю ошибку elasticsearch.exceptions.NotFoundError: NotFoundError (404, 'index_not_found_exception', 'no such index', cars, index_or_alias)

Хотя такая запись находится в базе данных. Что может быть причиной. Запускаю проект по порту 8001.

def search(request):
    json_data = json.loads(request.body)
    title = json_data['title'] if 'title' in json_data else ''
    note_text = json_data['note_text'] if 'note_text' in json_data else ''
    publication_type = json_data['publication_type'] if 'publication_type' in json_data else ''
    mesh_terms = json_data['mesh_terms'] if 'mesh_terms' in json_data else ''
    conditions = json_data['conditions'] if 'conditions' in json_data else ''
    comments = json_data['comments'] if 'comments' in json_data else ''
    more = json_data['more']

    posts = ArticleDocument.search()
    if title and title != '':
        posts = posts.query("match", title=title.lower())
    if note_text and note_text != '' :
        posts = posts.query("match", note_text=note_text.lower())
    if comments and comments != '':
        posts = posts.query("match", comments=comments)
    if publication_type and publication_type != '':
        posts = posts.query("match", publication_type=publication_type.lower())
    if mesh_terms and mesh_terms != '':
        posts = posts.query("match", mesh_terms=mesh_terms)
    if conditions and conditions !='':
        posts = posts.query("match", conditions=conditions)

    posts = posts.extra(from_=0, size=more)

    resdata = []
    for hit in posts:
        resdata.append({"title":hit.title, "id":hit.index})
    return JsonResponse({'code':1, 'data':resdata, 'msg':"Success"})

ArticleDocument

@registry.register_document
class ArticleDocument(Document):
    class Index:
        # Name of the Elasticsearch index
        name = 'cars'
        # See Elasticsearch Indices API reference for available settings
        settings = {'number_of_shards': 1,
                    'number_of_replicas': 0}

    class Django:
        model = Article # The model associated with this Document

        # The fields of the model you want to be indexed in Elasticsearch
        fields = [
            'title',
            'index',
            'url',
            'note_text1',
            'date',
            'note_text',
            'full_text_link',
            'publication_type',
            'mesh_terms',
            'conditions',
            'comments',
            'note_html',
        ]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...