Django-elasticsearch-dsl does not return all records that match the query condition

I'm writing a site on Django. I'm developing a site search system using django-elasticsearch-dsl. But I noticed a problem that not all records that meet the search condition are displayed.

For example, I know that I have 6 books in my database that contain the word 'Python', but when I use the command

books = BookDocument.search().query('match', title='Python')

django-elasticsearch-dsl gives me only 3 entries

books = BookDocument.search().query('match', title='Python')
for i in books:
    print(i.title)

||||||||||||| 

Укус Python
Програмуємо на Python
Django:Практика створення Web-сайтів на Python

And the remaining 3 are not displayed

Here is my BookDocument class:

@registry.register_document
class BookDocument(Document):
    """
    Індексація таблиці БД Book для Elasticsearch-пошуку
    Згідно із документацією django-elasticsearch-dsl
    https://django-elasticsearch-dsl.readthedocs.io/en/latest/fields.html
    """
    image = FileField()
    category = ObjectField(properties={
        'title': TextField(),
        'pk': IntegerField()
    })
    authors = NestedField(properties={
        'pk': IntegerField(),
        'name': TextField()
    })

    class Index:
        name = 'book'
        settings = {
            'number_of_shards': 1,
            'number_of_replicas': 0
        }

    class Django:
        model = Book

        fields = [
            'id',
            'title',
            'description',
        ]
        related_models = [Category, Author]

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, Category):
            return related_instance.book_set.all()
        if isinstance(related_instance, Author):
            return related_instance.book_set.all()

Maybe someone has already encountered this and knows how to fix it

Back to Top