I am following the get-started tutorial of pyes, the code can finish, but there is no search results returned to my screen.
#!/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()
When I run the code, it only returns the hello world.
Totally new to elastic search and any feedback would be deeply appreciated!