def elastic_seeker1(): BookDoc = seeker.document_from_model(models.Book, index="seeker-tests", using=models.client) seeker.register(BookDoc) s = BookDoc.search() s = s.query("match_all") books = s.execute() for book in books: print(book.meta.score, book.authors) models.BookDoc = BookDoc
import elasticsearch_dsl as dsl import seeker from .external import BaseDocument from .models import Book, Magazine BookDocument = seeker.document_from_model(Book, module=__name__) MagazineDocument = seeker.document_from_model(Magazine, module=__name__) class DjangoBookDocument (seeker.ModelIndex): class Meta: mapping = seeker.build_mapping(Book, doc_type='django_book') @classmethod def queryset(cls): return Book.objects.filter(title__icontains='django') class DerivedDocument (BaseDocument): derived_field = dsl.Integer()
from .models import Book, Magazine import seeker BookDocument = seeker.document_from_model(Book) MagazineDocument = seeker.document_from_model(Magazine) seeker.register(BookDocument) seeker.register(MagazineDocument)
import elasticsearch_dsl as dsl import seeker from .external import BaseDocument from .models import Book, Magazine BookDocument = seeker.document_from_model(Book, module=__name__) MagazineDocument = seeker.document_from_model(Magazine, module=__name__) class DjangoBookDocument(seeker.ModelIndex): class Meta: mapping = seeker.build_mapping(Book) class Index: name = 'djangobook' @classmethod def queryset(cls): return Book.objects.filter(title__icontains='django') class DerivedDocument(BaseDocument): derived_field = dsl.Integer() class Index: name = 'derived'
from .models import Book, Magazine import seeker BookDocument = seeker.document_from_model(Book) MagazineDocument = seeker.document_from_model(Magazine) class DjangoBookDocument(seeker.ModelIndex): class Meta: mapping = seeker.build_mapping(Book, doc_type='django_book') @classmethod def queryset(cls): return Book.objects.filter(title__icontains='django') seeker.register(BookDocument) seeker.register(MagazineDocument) seeker.register(DjangoBookDocument)