下面是一个最小的例子。
我有一个包含以下记录的索引'test_index':
{u'name': u'b'}
{u'name': u'e'}
{u'name': u'a'}
{u'name': u'c'}
{u'name': u'd'}我想按'name'字段的字母顺序获取记录。我使用sort参数,但结果没有排序:
q = pyes.query.MatchAllQuery().search()
tuple(record['name'] for record in conn.search(q, indices = 'test_index', sort = 'name'))结果:
(u'b', u'c', u'd', u'e', u'a')我在这里做错了什么?
发布于 2013-11-14 23:57:40
编辑:问题创建者找到解决方案,并在评论中发布:
已经试过了,它不起作用。然而,我刚刚找到了解决方案,这是一个属性映射的问题--请看这个问题: stackoverflow.com/questions/18065667/elasticsearch-wont-sort
旧的:不幸的是,我不能在这里测试,但请尝试这个版本:
q = pyes.query.MatchAllQuery()
tuple(record['name'] for record in conn.search(q, indices = 'test_index', sort = 'name'))还要注意的是,现在有了用于弹性搜索的官方python api。
http://elasticsearch-py.readthedocs.org/en/latest/
https://stackoverflow.com/questions/19981117
复制相似问题