1

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

5
  • Hi, Do you guys think django-elasticsearch-dsl pkg does not support python 3.7. I just found out that in the below github tutorial, its is mentioned, it says "requirements = Python 2.7, 3.4, 3.5, 3.6". Iam using python 3.7. and it seems, I cant downgrade it either. Commented Oct 25, 2018 at 4:11
  • The error suggests that you have not applied migrations after defining your models. manage.py makemigrations && manage.py migrate. Commented Oct 25, 2018 at 4:27
  • Thanks for the reply. Hi yeah,I tried that also. But no luck . Besides, according to the tutorial, we do not have to do that. for my mysql tables, I have already did that. Commented Oct 25, 2018 at 4:58
  • Which version of django you are using? Commented Oct 25, 2018 at 9:01
  • Hi Pankaj, its Django 2.1.2 Commented Oct 25, 2018 at 23:38

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.