Optimus
Optimus

Reputation: 1

Django elasticsearch dsl not identifying the index i have created

I'm trying to implement elastic search in my website.

Problem: When I rebuild index, index is not identified. Actually it is not recognising the document itself. This has worked before.But now i get a prompt like this:Are you sure you want to delete the ' ' indexes? [n/Y]

packages:

elastic search version:7.6.2 elasticsearch==7.6.0 elasticsearch-dsl==7.1.0 django-elasticsearch-dsl==7.1.1

I have few Questions: 1) How to get url of the model for redirect after search? 2) How to use richtextfield in document? 3) Is it possible to include multiple model in a document?

@registry.register_document
class AboutUsDocument(Document):
    class Index:
        name = 'aboutus'
        settings = {'number_of_shards': 1,
                    'number_of_replicas': 0}

    class Django:
        model = AboutUs 

        fields = ['our_story','second_section', 'third_section',
                  'fourth_section', 'five_section','published',
                 ]

Upvotes: 0

Views: 2343

Answers (2)

mohamadhosseintahan
mohamadhosseintahan

Reputation: 58

you should define your search in the view and call your document if you just create document and call "python manage.py search_index --rebuild",elasticsearch can not recognize the index that you have written in documents file. But if you define your search like " AboutUsDocument.search().query('match_all') " in the view the elastichsearch server can write the index in itself.

Upvotes: 1

Omar Al-Howeiti
Omar Al-Howeiti

Reputation: 1305

You should make sure that the python file which contains the document registration is have the name documents.

cause the library will look for that file in your app, if you have different name for it, the library will not recognize it.

here is the line where it will look for documents file:

def autodiscover():
    autodiscover_modules('documents')

Upvotes: 1

Related Questions