1

I am trying to read / write to elasticsearch using Django REST framework.

As a result of investigation, I found the following method using Elasticsearch DSL.

elasticsearch-with-django-the-easy-way

However, this method is written to the DB at the same time as elasticsearch. How can I write this in only elasticsearch?

I'm sorry. My English is not very strong.

1

1 Answer 1

0

If you want to find framework for REST Django and elasticsearch connection you can check this one : http://django-rest-elasticsearch.readthedocs.io/en/latest/index.html. And if you wanna to create NoSQL solution for guide which you found, you should create Django app without models and just indexed your elasticsearch data from json or .tsv/.csv file using elasticsearch-dsl. It will be something like :

class ElementIndex(DocType):
    ROWNAME = Text()
    ROWNAME = Text()

    class Meta:
        index = 'index_name'

def indexing(self):
    obj = ElementIndex(
        ROWNAME=str(self['NAME']),
        ROWNAME=str(self['NAME'])
    )
    obj.save(index="index_name")
    return obj.to_dict(include_meta=True)

def bulk_indexing(args):

    # ElementIndex.init(index="index_name")
    ElementIndex.init()
    es = Elasticsearch()

    //here your result dict with data from source

    r = bulk(client=es, actions=(indexing(c) for c in result))
    es.indices.refresh()

And as i said you can use REST with elastic from link above. Then create your Django templates or use ReactJS or something else to create frontend.

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

3 Comments

no need to call obj.save(index="index_name"), bulk will do it
By creating 'ElementIndex' , throws error 'AttributeError: type object 'Meta' has no attribute 'model'', can you please help?
@AALAPJETHWA Maybe Django version issue? stackoverflow.com/questions/32693512/…

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.