I'd like to use the elasticsearch-dsl 0.0.9 librairy however their example are out of date. I installed the lastest version and the Integer and Boolean type do not exist anymore.
Thus their example is not working.
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
Would anyone know how to declare a Integer field?
Thanks.
According to this document https://media.readthedocs.org/pdf/elasticsearch-dsl/latest/elasticsearch-dsl.pdf the Integer type should still be available in 0.0.9
I dont know why it won't find it.
As you can see from my pip output I did install the 0.0.9 : Downloading elasticsearch_dsl-0.0.9-py2.py3-none-any.whl
Field types like Float , Double , Byte , Integer , Boolean, IP, etc. are dynamic classes in elasticsearch-dsl
. The library itself creates these classes as mentioned in the source code. Posting sample code from the file here for quick reference. For complete reference you can check out the file 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 is a tuple containing all these field types. So basically to answer your question, your IDE will show the classes as not available , but when you will run the code , they will get created automatically.
Check from line #212 here.