Pyes弹性搜索没有结果返回

时间:2013-10-12 20:39:15

标签: python elasticsearch pyes

我正在按照pyes的入门教程,代码可以完成,但没有搜索结果返回到我的屏幕。

#!/usr/bin/python
from pyes import *

def main():
    print 'hello world'
    conn = ES('127.0.0.1:9200')
    # delete the existing index/database and create the new one
    try:
        conn.indices.delete_index("test")
    except:
        pass
    conn.indices.create_index("test")

    mapping = {
            'mpn':{
                    'index': 'analyzed',
                    'store': 'yes',
                    'type': 'string'
            },
            'manufacturer':{
                        'index': 'analyzed',
                        'store': 'yes',
                        'type': 'string'
            },
            'timestamp':{
                    'type': 'date'
            },
            'stock':{
                    'store': 'yes',
                    'type': 'integer'
            },
            'price':{
                    'store': 'yes',
                    'type': 'float'
            }
    }

    conn.indices.put_mapping("test-type", {'properties':mapping}, ["test"])


    conn.index({'mpn':'apple', 'manufacturer':'manufacturer1', 'timestamp':'2009-11-15T14:12:12', 'stock':100, 'price':1.2}, "test", "test-type", 1)
    conn.index({'mpn':'apple', 'manufacturer':'manufacturer1', 'timestamp':'2009-11-16T14:12:12', 'stock':99, 'price':1.2}, "test", "test-type", 2)
    conn.index({'mpn':'apple', 'manufacturer':'manufacturer1', 'timestamp':'2009-11-17T14:12:12', 'stock':90, 'price':1.2}, "test", "test-type", 3)
    conn.index({'mpn':'apple', 'manufacturer':'manufacturer1', 'timestamp':'2009-11-18T14:12:12', 'stock':140, 'price':1.2}, "test", "test-type", 4)

    conn.indices.refresh("test")

    q = TermQuery('mpn', 'apple')
    results = conn.search(query=q)
    for result in results:
        print result

if __name__ == '__main__':
    main()

当我运行代码时,它只返回hello世界。

对弹性搜索完全陌生,任何反馈都会深深体会!

0 个答案:

没有答案