用于ElasticSearch集成的类Django模型管理器
elasticmanager的Python项目详细描述
#elasticmanager
用于将orm转换为elasticsearch的管理器
*此包仍在积极开发中。目前,它正在为Django ORM制造混合机。但是,一旦稳定,这个包将被抽象出来,以便能够插入到其他orms中。*
这个包需要“elasticsearch dsl”,您可以获得:
\getting started
1。要开始,请从pip安装。
1。将“elasticmanager”添加到“settings.py”(这将启用管理命令)。
1.将索引的名称放入“settings.py”:“elasticsearch”index=“myindex”`
1。子类'elasticmanager.elasticmodel`.
`` python
来自django.db import models
来自elasticmanager.models import elasticmodel
类访问者(elasticmodel,models.model):
name=models.charfield(max-lendth=100)
created=models.datetimefield(auto-now-add=true,可编辑=false)
````
1.在与相应的“models.py”应用程序相同的应用程序中创建“doctypes.py”。
将“doctype”添加到与模型同名的文件中。(有关创建“doctype”的详细信息,请参见[elasticsearch dsl documenation](https://elasticsearch dsl.readthedocs.io/en/latest/persistence.html\doctype))
``python
from django.conf import settings
from elasticmanager.doctype import basedoctype
from。导入模型
class visitor(basedoctype):
name=field.keyword()
created=field.date()
class meta:
model=models.visitor
index=settings.elasticsearch\u index
````
` doctype应该链接到model和index。运行`./manage.py rebuild_mapping`
1。运行(如果数据库中有需要重新编译的项目),则还有另一个管理命令(可以为删除整个索引)。在开发阶段有帮助。
BR/>当前,模型的实例中对“.SAVER())方法的所有调用将触发DOCTYPE上的“.SaveE()”,因此将使索引在弹性搜索中保持最新。
BR/> *调用查询和筛选
BR/>调用有点近似默认Django语法。
BR/**GET全部实例**
`` python
visitors=visitor.elastic.all();返回来自elasticsearch的所有内容queryset中的第一个实例[查询](https://elasticsearch dsl.readthedocs.io/en/latest/search-dsl.html查询)和[筛选](https://elasticsearch dsl.readthedocs.io/en/latest/search-dsl.html筛选)方法。有关详细信息,请参阅链接的文档。*
`` python
johns=visitor.elastic.filter(name=“john”)返回所有来自elasticsearch的内容正在进行搜索。这可以自己调用,如果您正在(例如)操作queryset,则可能应该调用它。但是,如果您正在调用count(),或者正在对结果集进行迭代,则不需要调用该函数。
``python
johns=visitor.elastic.filter(name=“john”)
johns:print(john)
或者
johns=visitor.elastic.filter(name=“john”)
johns.execute()
print(johns.results)
``````
>
>
>
>
>
>>
>>
==>这一要求将通过一些更精细的调整来消除,使工作更直观地工作更直观地进行,这一要求。*
是的未来
-使用“models.manager”的抽象
-修复类工厂,以便“model”可以自动转换为“doctype”,而无需在“doctypes.py”中定义它。
-测试
-聚合
-附加异常处理
-更多管理命令
-更强大的api
任何问题,想法,抱怨,恭维,让我知道。
用于将orm转换为elasticsearch的管理器
*此包仍在积极开发中。目前,它正在为Django ORM制造混合机。但是,一旦稳定,这个包将被抽象出来,以便能够插入到其他orms中。*
这个包需要“elasticsearch dsl”,您可以获得:
\getting started
1。要开始,请从pip安装。
1。将“elasticmanager”添加到“settings.py”(这将启用管理命令)。
1.将索引的名称放入“settings.py”:“elasticsearch”index=“myindex”`
1。子类'elasticmanager.elasticmodel`.
`` python
来自django.db import models
来自elasticmanager.models import elasticmodel
类访问者(elasticmodel,models.model):
name=models.charfield(max-lendth=100)
created=models.datetimefield(auto-now-add=true,可编辑=false)
````
1.在与相应的“models.py”应用程序相同的应用程序中创建“doctypes.py”。
将“doctype”添加到与模型同名的文件中。(有关创建“doctype”的详细信息,请参见[elasticsearch dsl documenation](https://elasticsearch dsl.readthedocs.io/en/latest/persistence.html\doctype))
``python
from django.conf import settings
from elasticmanager.doctype import basedoctype
from。导入模型
class visitor(basedoctype):
created=field.date()
class meta:
model=models.visitor
index=settings.elasticsearch\u index
````
` doctype应该链接到model和index。运行`./manage.py rebuild_mapping`
1。运行(如果数据库中有需要重新编译的项目),则还有另一个管理命令(可以为删除整个索引)。在开发阶段有帮助。
BR/>当前,模型的实例中对“.SAVER())方法的所有调用将触发DOCTYPE上的“.SaveE()”,因此将使索引在弹性搜索中保持最新。
BR/> *调用查询和筛选
BR/>调用有点近似默认Django语法。
BR/**GET全部实例**
`` python
visitors=visitor.elastic.all();返回来自elasticsearch的所有内容queryset中的第一个实例[查询](https://elasticsearch dsl.readthedocs.io/en/latest/search-dsl.html查询)和[筛选](https://elasticsearch dsl.readthedocs.io/en/latest/search-dsl.html筛选)方法。有关详细信息,请参阅链接的文档。*
`` python
johns=visitor.elastic.filter(name=“john”)返回所有来自elasticsearch的内容正在进行搜索。这可以自己调用,如果您正在(例如)操作queryset,则可能应该调用它。但是,如果您正在调用count(),或者正在对结果集进行迭代,则不需要调用该函数。
``python
johns=visitor.elastic.filter(name=“john”)
johns:print(john)
或者
johns=visitor.elastic.filter(name=“john”)
johns.execute()
print(johns.results)
``````
>
>
>
>
>
>>
>>
==>这一要求将通过一些更精细的调整来消除,使工作更直观地工作更直观地进行,这一要求。*
是的未来
-使用“models.manager”的抽象
-修复类工厂,以便“model”可以自动转换为“doctype”,而无需在“doctypes.py”中定义它。
-测试
-聚合
-附加异常处理
-更多管理命令
-更强大的api
任何问题,想法,抱怨,恭维,让我知道。