-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbulk_fix.py
51 lines (46 loc) · 1.54 KB
/
bulk_fix.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
42
43
44
45
46
47
48
49
50
51
from elasticsearch import Elasticsearch
from elasticsearch import helpers
import json
import os
import json
from datetime import datetime
import urllib
import os
dir = '../socialsandbox/isil/'
users = {}
chunksize = 1000
badfile = open('bad_baltimore','w')
allfile = open('all.csv','w')
def deleteImages(users):
howmany = 0
for id in users.keys():
users[id]["geoloc"]["lat"] = users[id]["location"]["latitude"]
users[id]["geoloc"]["lon"] = users[id]["location"]["longitude"]
print 'yep'
howmany += 1
es.index(index="instagram_remap",doc_type="baltimore",id=id,body=users[id])
print howmany
def addUsers(response):
for i in response["hits"]["hits"]:
lat = i['_source']["location"]["latitude"]
lon = i['_source']["location"]["longitude"]
madelat = i['_source']["geoloc"]["lat"]
madelon = i['_source']["geoloc"]["lon"]
if lat == madelon and lon == madelat:
users[i['_id']] = i['_source']
es = Elasticsearch(['http://10.1.94.103:9200/'])
query={"size":chunksize,"query" : {"match_all" : {}}}
scanResp= es.search(index="instagram_remap", doc_type="baltimore", body=query, search_type="scan", scroll="10m")
scrollId= scanResp['_scroll_id']
response= es.scroll(scroll_id=scrollId, scroll= "10m")
addUsers(response)
count = len(response["hits"]["hits"])
scrollId = response['_scroll_id']
print count
while response["hits"]["hits"]:
response= es.scroll(scroll_id=scrollId, scroll= "10m")
addUsers(response)
scrollId = response['_scroll_id']
count += len(response["hits"]["hits"])
print count
deleteImages(users)