-
Notifications
You must be signed in to change notification settings - Fork 3
/
addtoes.py
36 lines (24 loc) · 954 Bytes
/
addtoes.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
from elasticsearch import Elasticsearch
from elasticsearch.client import IndicesClient
from trump import SymbolManager
es = Elasticsearch([{'host': 'localhost', 'port':9200}])
ic = IndicesClient([{'host': 'localhost', 'port':9200}])
from equitable.db.psyw import SQLAeng
sme = SQLAeng('Trump','PROD')
sm = SymbolManager(sme)
syms = sm.search()
mapping = {
'properties': {
'name': {'type': 'string', 'index': 'not_analyzed' },
'tags': {'type': 'string', 'index': 'not_analyzed' },
'description': {'type': 'string'},
'meta' : {'type' : 'nested'}
}
}
if es.indices.exists(index='trump'):
es.indices.delete(index='trump')
es.indices.create(index='trump')
es.indices.put_mapping(index='trump', doc_type='symbol', body=mapping)
for i, sym in enumerate(syms):
print sym.name
es.index(index='trump', doc_type='symbol', id=i, body=sym.to_json())