Skip to content

Instantly share code, notes, and snippets.

@mindflayer
Created March 13, 2015 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindflayer/9fb66103b00791dc9be2 to your computer and use it in GitHub Desktop.
Save mindflayer/9fb66103b00791dc9be2 to your computer and use it in GitHub Desktop.
TypeError: unhashable type: 'list'
from elasticsearch_dsl import query
q = {'bool': {'must': [{'term': {'customer_id_list': u'es_igames'}}], 'minimum_number_should_match': 1, 'should': [{'query_string': {'minimum_should_match': '30%', 'fields': [u'meta_es_igames.title^5', u'meta_es_igames.es.title^5', u'meta_es_igames.artist_name_list^3', u'meta_es_igames.author_name_list^3', u'meta_es_igames.album_name_list^2', u'meta_es_igames.es.abstract^2', u'meta_es_igames.es.description'], 'default_operator': 'OR', 'use_dis_max': False, 'query': u'debug'}}, [{'term': {u'meta_es_igames.es.title': u'debug'}}, {'prefix': {u'meta_es_igames.es.title': u'debug'}}, {'fuzzy': {u'meta_es_igames.es.title': u'debug'}}, {'term': {'publisher': u'debug'}}, {'prefix': {'publisher': u'debug'}}, {'fuzzy': {'publisher': u'debug'}}, {'term': {'cs_id': u'debug'}}]]}}
query.Q(q)
@mindflayer
Copy link
Author

Traceback (most recent call last):
File "debug.py", line 5, in
query.Q(q)
File "/tmp/debug/local/lib/python2.7/site-packages/elasticsearch_dsl/query.py", line 13, in Q
return Query.get_dsl_class(name)(**params)
File "/tmp/debug/local/lib/python2.7/site-packages/elasticsearch_dsl/utils.py", line 189, in init
self._setattr(pname, pvalue)
File "/tmp/debug/local/lib/python2.7/site-packages/elasticsearch_dsl/utils.py", line 226, in _setattr
value = list(map(shortcut, value))
File "/tmp/debug/local/lib/python2.7/site-packages/elasticsearch_dsl/query.py", line 22, in Q
return Query.get_dsl_class(name_or_query)(**params)
File "/tmp/debug/local/lib/python2.7/site-packages/elasticsearch_dsl/utils.py", line 180, in get_dsl_class
return cls._classes[name]
TypeError: unhashable type: 'list'

@mindflayer
Copy link
Author

$ pip freeze
argparse==1.2.1
elasticsearch==1.4.0
elasticsearch-dsl==0.0.3
python-dateutil==2.4.1
six==1.9.0
urllib3==1.10.2
wsgiref==0.1.2

@mindflayer
Copy link
Author

I've just found I have the list of 'should' queries, with a nested array in the main one. The funny thing is that is a production query, and Elasticsearch consumes it correctly.
I'm fixing the query with a flat 'should' array, but I think the library should not end up with an unmanaged exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment