-
Notifications
You must be signed in to change notification settings - Fork 1
/
searcher.py
41 lines (33 loc) · 1.11 KB
/
searcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
import sys
from os import environ
from elasticsearch import Elasticsearch, RequestsHttpConnection
from requests_aws4auth import AWS4Auth
# hack to deal with encoding issue
reload(sys)
sys.setdefaultencoding('UTF8')
host = environ['es_host']
awsauth = AWS4Auth(environ['aws_key'],
environ['aws_secret'],
environ['aws_region'], 'es')
es = Elasticsearch(hosts=[{'host': host, 'port': 443}],
http_auth=awsauth,
use_ssl=True,
verify_certs=True,
connection_class=RequestsHttpConnection)
if __name__ == '__main__':
# define structure
request_body = {
'mappings': {
'tweet': {
'properties': {
'user_name': {'type': 'string'},
'screen_name': {'type': 'string'},
'text': {'type': 'string'},
'location': {'type': 'geo_point'},
'date': {'type': 'string'}
}
}
}
}
es.indices.create(index='tweets', body=request_body)