liberation / django-elasticsearch

Simple wrapper around elasticsearch-py to index/search a django Model.
MIT License
212 stars 73 forks source link

How to use some operators. #43

Closed onegreyonewhite closed 8 years ago

onegreyonewhite commented 8 years ago

Sorry, for my question. How to filter by fields "must" and "range"? I used

q = Traps.es.all().filter(time__gte="now-10d") q.filter(severity="ERROR") but it tell me raise

RequestError: TransportError(400, u'search_phase_execution_exception', u'No query registered for [must]')

How to get range and must fields filter?

P.S.: query search create {'query': {'filtered': {'filter': {'range': {'time': {'gte': 'now-10d'}}, 'bool': {'must': [{'term': {'severity': 'error'}}]}}}}}

lauxley commented 8 years ago

Hello, the syntax is correct, the must filter of Elasticsearch is mapped to __exact of Django and range to gt, gte, etc.. So it seems that either the query is not generated properly (bug) or the used version of pyelasticsearch is not matching your elasticsearch install ? I will investigate.

lauxley commented 8 years ago

I pushed a fix, let me know if it works for you.

onegreyonewhite commented 8 years ago

Thank you so much! It works! `>> Traps.es.all().filter(time__gte=last.isoformat(), severity="ERROR", server="test")

{'query': {'filtered': {'filter': {'bool': {'must': [{'range': {'time': {'gte': '2016-04-08T11:17:26.100360'}}}, {'term': {'severity': 'ERROR'}}, {'term': {'server': 'test'}}]}}}}, 'size': 1000}

[{u'obj': u'None', u'severity': u'ERROR', u'param': u'test', u'server': u'test', u'time': u'2016-04-08T11:59:43.286331', u'msg': u''}]`

I add "size" to query body in your module, because only 10 results returns basicly. You can add additional attribute in EsIndexable class for development convenience.

Thank you for help and this project :)