Elasticsearch data layer for eve framework
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
eve_elastic
scripts
test
.gitignore
.travis.yml
AUTHORS.md
CHANGELOG.rst
LICENSE
MANIFEST.in
README.rst
requirements.txt
setup.cfg
setup.py

README.rst

Eve-Elastic

https://travis-ci.org/petrjasek/eve-elastic.png?branch=master

Eve-Elastic is elasticsearch data layer for eve REST framework.

Features

  • fulltext search
  • filtering via elasticsearch filter dsl
  • facets support
  • aggregations support
  • elasticsearch mapping generator for schema

License

Eve-Elastic is GPLv3 licensed.

Supported elastic versions

It supports 1.7 and 2.x versions. If you limit your queries to those which work with both you can have single codebase for both.

Install

$ pip install Eve-Elastic

Usage

Set elastic as your eve data layer.

import eve
from eve_elastic import Elastic

app = eve.Eve(data=Elastic)
app.run()

Config

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 urls
  • ELASTICSEARCH_INDEX - (default: 'eve')
  • ELASTICSEARCH_INDEXES - (default: {}) - resource to index mapping
  • ELASTICSEARCH_FORCE_REFRESH - (default: True) - force index refresh after every modification
  • ELASTICSEARCH_AUTO_AGGREGATIONS - (default: True) - return aggregates on every search if configured for resource

Query params

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)

Filtering

For more sophisticated filtering, you can use filter query param which will be used as filter for the query, using elastic filter dsl.

Facets

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.