Django Elasticsearch DSL


1. Create an Index

from django_elasticsearch_dsl import Document, Index, fields

class Article(Document):
    title = fields.TextField()
    content = fields.TextField()

    class Index:
        name = 'articles'

2. Serializing a Django Model

class ArticleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Article
        fields = ['id', 'title', 'content']

3. Search using DSL

from django_elasticsearch_dsl import search

search.index('articles').query("match", title="Django")

4. Filter Results

5. Pagination

6. Faceting

7. Aggregations

8. Completion Suggester

9. Synonym Filter

10. Geo Distance

11. Create Index Template

12. Define a Search Index

13. Index a Django Model

14. Search Documents

15. Create an Autocomplete Index

16. Add a Suggester to a Field

17. Add a Mapping to a Field

18. Index a Model with Multimatch Query

19. Index a Model with Filtering

20. Index a Model with Sorting

21. Create an Index with Custom Analyzer

22. Create an Index with Custom Tokenizer

23. Create an Index with Custom Filter

24. Create an Index with Custom Char Filter

25. Create an Index with Custom Token Filter

26. Create an Index with Custom Synonym Filter

27. Create an Index with Custom Edge Ngram Tokenizer