使用elasticsearch-dsl创建一个Integer字段的DocType类
问题描述:
我想使用elasticsearch-dsl 0.0.9 librairy,但是它们的示例已过时。 我安装了最新版本,整数和布尔类型不再存在。使用elasticsearch-dsl创建一个Integer字段的DocType类
因此,他们的例子不起作用。
from datetime import datetime
#There is no 'Integer' in elasticsearch_dsl
from elasticsearch_dsl import DocType, String, Date, Integer
from elasticsearch_dsl.connections import connections
# Define a default Elasticsearch client
connections.create_connection(hosts=['localhost'])
class Article(DocType):
title = String(analyzer='snowball', fields={'raw': String(index='not_analyzed')})
body = String(analyzer='snowball')
tags = String(index='not_analyzed')
published_from = Date()
lines = Integer() ############################## HERE
有人会知道如何声明一个Integer字段吗?
谢谢。
编辑
根据这一文件https://media.readthedocs.org/pdf/elasticsearch-dsl/latest/elasticsearch-dsl.pdf Integer类型应该还是可以在0.0.9
我不知道为什么它不会找到它。
正如你可以从我的PIP输出看到我没有安装0.0.9:在elasticsearch-dsl
Downloading elasticsearch_dsl-0.0.9-py2.py3-none-any.whl
答
字段类型,如浮点,双精度,字节,整型,布尔,IP等都是动态类。库本身就像源代码中提到的那样创建这些类。从这里发布示例代码以供快速参考。有关完整参考,您可以查看文件elasticsearch_dsl/field.py
。
# generate the query classes dynamicaly
for f in FIELDS:
fclass = _make_dsl_class(Field, f)
globals()[fclass.__name__] = fclass
__all__.append(fclass.__name__)
FIELDS是一个包含所有这些字段类型的元组。所以基本上要回答你的问题,你的IDE会显示这些类不可用,但是当你运行代码时,它们会自动创建。
从行#212 here检查。
oooh,谢谢。 –