liberation / django-elasticsearch

Simple wrapper around elasticsearch-py to index/search a django Model.
MIT License
212 stars 73 forks source link

Delete issue- appear at `/_search` but not at `/123` #75

Open yarnball opened 7 years ago

yarnball commented 7 years ago

Hi,

ES and django seem to work fine except for deleting items. When delete an item, I can no longer access it via it's pk (eg localhost:9200/django/model-X/123). It returns "false".

However, it still appears at localhost:9200/django/model-X/_search. The hits total do not change when I delete an item.

Is there a particular way to remove items form the _search that is different from accessing them at their individual URL?

lauxley commented 7 years ago

Hello, in Elasticsearch, when you issue an Index, Update or Delete command, you have to wait until the next refresh for the changes to be available, do you still have the issue after manually refreshing the index ? MyModel.es.do_update()

yarnball commented 7 years ago

Ok thanks, i've done your suggestion. I'm calling it in models.py. Let me know if there's anything wrong with it:

class Test(EsIndexable, models.Model):
    title = models.CharField("Title", max_length=10000, blank=True)
    created = models.DateTimeField("Created", auto_now=False)
    updated = models.DateTimeField(auto_now=False)

    class Elasticsearch(EsIndexable.Elasticsearch):
        serializer_class = TestEsSerializer
        fields = ['title', 'created', 'updated']

@receiver(post_save, sender= Test)
@receiver(post_delete, sender= Test)
def index_test(instance, **kwargs):
    Test.es.do_update()