An Elastic Search Query Parser
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
plasticparser
tests
.gitignore
LICENSE
README.md
circle.yml
dev-requirements.txt
requirements.txt
run_tests.sh
setup.py

README.md

plasticparser

Circle CI

An Elastic Search Query Parser

Installation

$ pip install plasticparser

Usage

from plasticparser import plasticparser

query_string = 'type:candidates (name:"John Doe" starred:true) (python or java) facets:[location]'
global_filters = {
            'and': [{"client_id": 1},
                    {"user_id": 2}],
            'or': [],
            'not': [],
            'sort': [{"created_on": "desc"}]
        }
print plasticparser.get_query_dsl(query_string, global_filters)
{
    'query': {
        'filtered': {
            'filter': {
                'bool': {
                    'must': [
                        {
                            'type': {'value': 'candidates' }
                        },
                        {
                            'term': {'client_id': 1}
                        },
                        {
                            'term': {'user_id': 2}
                        }
                    ],
                    'must_not': []
                }
            },
            'query': {
                'query_string': {'query': u'(name:\\"John Doe\\" AND starred:true) AND (python OR java)'}
            }
        }
    },
    'facets': {
        'location': {
            'terms': {
                'field': 'location'
            }
        }
    },
    'sort': [
        {'created_on': 'desc'}
    ]
}