plasticparser

An Elastic Search Query Parser


Keywords
elasticsearch, query, language, parser
License
MIT
Install
pip install plasticparser==0.3.3

Documentation

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'}
    ]
}