I have a scientific research publications data of 2 Million records. I used django restframework to write apis for searching the data in title
and abstract
. This is taking me 12 seconds
while using postgres
as db, but if I used MongoDB
as db, it goes down to 6seconds
.
But even 6 seconds sounds a lot of waiting for user to me. I indexed the title
and abstract
, but abstract indexing failed because some of the abstract texts are too lengthy.
Here is the django Model using MongoDB(MongoEngine as ODM):
class Journal(Document):
title = StringField()
journal_title = StringField()
abstract = StringField()
full_text = StringField()
pub_year = IntField()
pub_date = DateTimeField()
pmid = IntField()
link = StringField()
How do I improve the query performance, what stack makes the search and retrieval more faster?.
Some pointers about optimisation for the Django ORM with Postgres:
db_index=True
on fields that will be search upon often and have some degree of repetition between entries, like "title". values()
and values_list()
to select only the columns you want from a QuerySet. contains
query), bear in mind that Django has support for full text search directly on a Postgres database . print queryset.query
to check what kind of SQL query is going into your database and if it can be improved upon. RawSQL
expressions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.