本文介绍了Django-使用PostgreSQL和Elasticsearch进行全文搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个 Django 和 Django REST Framework 支持的RESTful API(与对话) PostgreSQL 数据库后端),它支持对特定模型进行过滤。I have a Django and Django REST Framework powered RESTful API (talking to a PostgreSQL DB backend) which supports filtering on a specific model.现在,我想添加全文搜索功能。Now I want to add a fulltext search functionality.是否可以使用 Elasticsearch 进行全文搜索,然后在这些搜索结果之上应用我现有的API过滤器?Is it be possible to use Elasticsearch for fulltext search and then apply my existing API filters on top of these search results?推荐答案我建议您考虑只使用 PostgreSQL 来满足您的要求。I would suggest you consider using PostgreSQL only to do what you asked for.我认为这是最好的解决方案,因为您将直接在 PostgreSQL 内部拥有数据和搜索索引,并且不会被迫安装和维护其他软件(例如作为 Elasticsearch ),并使数据和索引保持同步。In my opinion it is the best solution because you will have the data and the search indexes directly inside PostgreSQL and you will not be forced to install and maintain additional software (such as Elasticsearch) and keep the data and indexes in sync.这是您必须执行全文搜索(在Django中使用PostgreSQL:This is the simplest code example you can have to perform a full-text search in Django with PostgreSQL:Entry.objects.filter(body_text__search='Cheese')有关使用的所有基本文档在带有PostgreSQL的Django中href = https://stackoverflow.com/questions/tagged/django+postgresql+full-text-search>全文搜索,您可以使用官方文档: 全文搜索 For all the basic documentation on using the full-text search in Django with PostgreSQL you can use the official documentation: "Full text search"如果您想进一步加深,可以阅读我写的关于该主题的文章:If you want to deepen further you can read an article that I wrote on the subject: 全文使用PostgreSQL在Django中搜索 "Full-Text Search in Django with PostgreSQL" 这篇关于Django-使用PostgreSQL和Elasticsearch进行全文搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-21 03:25