Package: elastic-dql
Elastic-dqlAdvanced search language for Django and elasticsearch based on DjangoQL project.DjangoQL is a library that provides search language that works with django orm. elastic-dql extends DjangoQL project to
generate elasticsearch queries.elastic-dql suppports logical operators and parenthesis.It also provides to apis to get index mappings and value
suggestions for keyword fields.ContentsInstallationGenerating Elasticsearch QueriesCustom SchemaFactoryMappings and Suggestions (auto-complete) apiFeaturesTODO TasksDjangoQL projectLanguage referenceLicenseInstallation$pipinstallelastic-dqlAdd'elastic_dql'toINSTALLED_APPSin yoursettings.py:INSTALLED_APPS=[...'elastic_dql',...]AddELASTIC_DQLsection insettings.py:ELASTIC_DQL={"schema_factory":"elastic_dql.schema.SchemaFactory","default_schema":"elastic_dql.schema.ElasticDjangoQlSchema","default_index":None,"accept_index_param":True,# if False default_index should be specified"connection":{"hosts":["http://localhost"],}}this values are default configs.if you have just one elasticsearch index you better set a default index otherwise you
should passindexparameter inmappingsandsuggestionsapis.Generating Elasticsearch Queriesto create elasticsearch queries you should follow these lines:fromelastic_dql.queryimportget_queryindex_name="your_elasticsearch_index"query='name = "mohammad" and age = 10'elastic_query=get_query(index_name,query)Custom SchemaFactorySchemaFactory handles limits to access elasticsearch.by default elastic-dql useselastic_dql.schema.SchemaFactoryand allows to access to all indexes and fields.To make some limits at first you should create custom SchemaFactory:fromelastic_dql.schemaimportSchemaFactoryclassCustomSchemaFactory(SchemaFactory):include_indices=('*',)exclude_indices=()index_field_limits={"some-index":["password_field","other_limited_field"]}after implementingCustomSchemaFactoryadd the class path tosettings.py:ELASTIC_DQL={"schema_factory":"path.to.CustomSchemaFactory",...}:warning:you must either fill include_indices or exclude_indices not bothMappings and Suggestions apiMappings api: provides field mappings of index (default_index or get from url parameters)Suggestions api: provides field value suggestion forKeywordfields.can use for auto-complete.To use this apis you must add elastic_dql urls:fromelastic_dql.urlsimportget_urlsurlpatterns=[...]+get_urls()ORfromdjango.urlsimportincludeurlpatterns=[...include("elastic_dql.urls"),...]$curllocalhost:8000/mappings?index=your_index:warning:if use default_index, index parameter will be skipped$curllocalhost:8000/suggestions/some_keyword_field?index=your_index&search=values_must_contains_this:warning:search is optional - if use default_index, index parameter will be skippedFeaturesindex and field limiting withSchemaFactoryCustomizationmappings and suggestions apisTODO Tasksadd pagination to suggestions apimake library compatible with elastic-dsl query generatoradd async for elasticsearch communicationscache field mappings and invalidate it with user defined durationcompatibility test with some elasticsearch (python lib) versionshandle all elasticsearch fields now it supports (long,unsigned_long,text,keyword,float,int,date,boolean)DjangoQL projectDjangoQL github page:DjangoQLLanguage referenceThe query language is as same as djangoql query languageLanguage refrenceLicenseMIT