elasticsearch:NotFoundError

已安装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',]
wxcool87 回答:elasticsearch:NotFoundError

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3167512.html

大家都在问