Sasha
Sasha

Reputation: 87

error rebuilding the index using django-elasticsearch-dsl

I am trying to connect to a existing index in my local elastic search engine. I am using django-elasticsearch-dsl package. I followed this tutorial to do that. https://github.com/sabricot/django-elasticsearch-dsl

please note that,I already developed my django app[website] with mysql database. I have some unstructured text data indexed in elastic-search. I want to develop this 'advanced search' HTML page for users querying data frpm elasticsearch.

I followed almost everything upto python manage.py search_index --rebuild but once I excute it it asked Are you sure you want to delete the 'website_data_discovery' indexes? [n/Y]: when I say n it will be aborted. when I say Y it gives a lengthy error saying django.db.utils.ProgrammingError: Table 'crdc.website_data_discovery' doesn't exist

This is my file structure.

crdc
website 
         ->__pycache__
         ->  media
         ->migrations
         ->static
         ->templates
         ->__init__.py
         ->admin.py
         ->apps.py
         ->documnets.py
         ->forms.py
         ->models.py
         ->tests.py
         ->urls.py
         ->views.py
manage.py

This is my settings.py/crdc.

###more codes here
INSTALLED_APPS = [
    'website.apps.WebsiteConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_elasticsearch_dsl',

]

ELASTICSEARCH_DSL={
    'default': {
        'hosts': 'localhost:9200'
    },
}
###more codes here

This is documents.py/website

from django_elasticsearch_dsl import DocType, Index
from .models import Data_Discovery

data_discovery = Index('website_data_discovery')
data_discovery.settings( number_of_shards = 5, number_of_replicas = 1,)

@data_discovery.doc_type
class Data_DiscoveryDocument(DocType):
    class Meta:
        model = Data_Discovery
        fields = ['extracted_text',  'source_type']

this is models.py/website

from django.db import models

class WebsiteRepository(models.Model):
 ##### mysql model 

class Documents(models.Model):
 #### mysql model

class Data_Deposite(models.Model):
#### mysql model


class Data_Discovery(models.Model):
## Elasticsearch model 

Any help would be greatly appreciated. Thanks

Upvotes: 1

Views: 5736

Answers (1)

Sasha
Sasha

Reputation: 87

I know this is late. But, I thought I should answer my own question, so that anyone face the same problem, can figure it out.

I created another App for Elastic search component.Yes, I created another App under the same project. And I followed this tutorial https://pypi.org/project/django-elasticsearch-dsl/ Then I called Elasticsearch view functions at views.py from the website App. It works perfectly now.

I am not a expert in Django or Elastic Search. So, I can not explain why it is not working as the previous attempt. I hope this helps to anyone who comes to this kind of situation.

Upvotes: 4

Related Questions