0

Here is a minimal example.

I have an index 'test_index' with the following records:

{u'name': u'b'}
{u'name': u'e'}
{u'name': u'a'}
{u'name': u'c'}
{u'name': u'd'}

I want to get the records in alphabetical order of the 'name' field. I use the sort argument, but the result is not sorted:

q = pyes.query.MatchAllQuery().search()
tuple(record['name'] for record in conn.search(q, indices = 'test_index', sort = 'name'))

Result:

(u'b', u'c', u'd', u'e', u'a')

What am I doing wrong here?

Joe
  • 2,994
  • 5
  • 31
  • 34
  • Can you try using sort = 'name:ASC' and sort = 'name:DESC' and tell us if there is any difference? Code looks correct imo. – MeiSign Nov 14 '13 at 15:54
  • 1
    Already tried it, it doesn't work. However, I just now found the solution, it was a problem with the attribute mapping - see this question: http://stackoverflow.com/questions/18065667/elasticsearch-wont-sort – Joe Nov 14 '13 at 15:57

1 Answers1

0

Edit: Question creator found the solution and posted it in the comments:

Already tried it, it doesn't work. However, I just now found the solution, it was a problem with the attribute mapping - see this question: stackoverflow.com/questions/18065667/elasticsearch-wont-sort

Old: Unfortunately I couldn't test it here but try this version pls:

q = pyes.query.MatchAllQuery()
tuple(record['name'] for record in conn.search(q, indices = 'test_index', sort = 'name'))

Also note that there is now an official python api for elastic search.

http://elasticsearch-py.readthedocs.org/en/latest/

MeiSign
  • 1,487
  • 1
  • 15
  • 39