Eve-Elastic is elasticsearch data layer for eve REST framework.
- fulltext search
- filtering via elasticsearch filter dsl
- facets support
- aggregations support
- elasticsearch mapping generator for schema
Eve-Elastic is GPLv3 licensed.
It supports elasticsearch versions > 6.0.
$ pip install Eve-Elastic
Set elastic as your eve data layer.
import eve
from eve_elastic import Elastic
app = eve.Eve(data=Elastic)
app.run()
There are 2 options for Eve-Elastic taken from app.config
:
ELASTICSEARCH_URL
(default:'http://localhost:9200/'
) - this can be either single url or list of urlsELASTICSEARCH_INDEX_PREFIX
- (default:''
) - this allows to store indeces with a different index name but keep the query endpoints the sameELASTICSEARCH_INDEXES
- (default:{}
) -resource
toindex
mappingELASTICSEARCH_FORCE_REFRESH
- (default:True
) - force index refresh after every modificationELASTICSEARCH_AUTO_AGGREGATIONS
- (default:True
) - return aggregates on every search if configured for resource
Eve-Elastic supports eve like queries via where
param which work as term filter.
On top of this, there is a predefined query_string query which does fulltext search.
$ curl http://localhost:5000/items?q=foo&df=name
q
- query (default:*
)df
- default field (default:_all
)
For more sophisticated filtering, you can use filter
query param which will be used as filter for the query,
using elastic filter dsl.
To add a facets support for specific resource, add facets
into its datasource
:
DOMAIN = {
'contacts': {
'datasource':
'facets': {
'urgency': {'terms': {'field': 'urgency'}},
'versioncreated': {'date_histogram': {'field': 'versioncreated', 'interval': 'hour'}}
}
}
}
You will find more info about facets in elasticsearch docs.
If you want to add features make sure you dont breake any tests.
You can run
$ make test
which installs dependencies in a virtual env in the tmp folder and runs all tests.
For code quality checks you can runs
$ make checks
Which checks for linting etc.
A lot of stuff has been changed in the newest elasticsearch. One of the biggest changes is the removal of mapping types. Therefore eve-elastic has been restructured so that for every resource a seperate index is created as recommended. This removes the need of a standard INDEX settings and later on the doc_type will get obsolete as well.
Settings and Mappings are now created per index and should be defined within the document mapping. See the TestElasticNestedObjectsAndSettings test case for an example.