__doc__ = '''ELASTICSEARCH SERVICE USAGE EXAMPLE.
Elasticsearch must be started. Also elasticsearch cocaine plugin must be properly configured.
'''

now = time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime(time.time()))

elastic = Service('elasticsearch')

##### INDEX #####
print('Index simple message with index "/twitter/tweet/1"')
data = {
    'user': '******',
    'post_date': now,
    'message': 'Hello, Elasticsearch!'
}
print('Result:', elastic.index(json.dumps(data), 'twitter', 'tweet', '1').get())
print('')

##### GET #####
print('And now get it')
print(elastic.get('twitter', 'tweet', '1').get())
print('')

##### INDEX GENERATE #####
print('Index simple message with id generated and get it')
data = {
    'user': '******',
    'post_date': now,
    'message': 'Hello!'
}
status, index = elastic.index(json.dumps(data), 'twitter', 'tweet').get()