3

我想使用 elasticsearch-dsl 0.0.9 库但是他们的例子已经过时了。我安装了最新版本,并且 Integer 和 Boolean 类型不再存在。

因此他们的例子是行不通的。

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

有人知道如何声明一个整数字段吗?

谢谢。

编辑

根据此文档https://media.readthedocs.org/pdf/elasticsearch-dsl/latest/elasticsearch-dsl.pdf整数类型在 0.0.9 中仍应可用

我不知道为什么它不会找到它。

正如您从我的 pip 输出中看到的那样,我确实安装了 0.0.9 :Downloading elasticsearch_dsl-0.0.9-py2.py3-none-any.whl

4

1 回答 1

3

Float、Double、Byte、Integer、Boolean、IP 等字段类型是elasticsearch-dsl. 如源代码中所述,库本身会创建这些类。在此处发布文件中的示例代码以供快速参考。如需完整参考,您可以查看该文件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 行检查。

于 2015-11-17T20:38:53.553 回答