Skip to content

Instantly share code, notes, and snippets.

Created March 30, 2014 01:26
Show Gist options
  • Save anonymous/9865823 to your computer and use it in GitHub Desktop.
Save anonymous/9865823 to your computer and use it in GitHub Desktop.
Pasted from IPython
f = open('_User.json','rb')
import json
data = json.loads(f.read())
f.close()
data
data[0]
data.keys()
data['results'][0]
data['results'][0].keys()
from pyes import *
conn = ES('localhost:9200')
conn.indices.create_index('takeZero')
conn.indices.create_index('take_zero')
data['results'][0].keys()
mapping = { u'username' : {'boost' : 1.0,
'index' : 'analyzed' ,
'store' : 'yes',
'type' : u'string',
"term_vector" : "with_positions_offsets"},
u'objectId' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'firstName' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'lastName' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'bcryptPassword' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'updatedAt' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'sessionToken' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'email' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'createdAt' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'summary' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'albums' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'headshot' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"}
u'profession' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
mapping = { u'username' : {'boost' : 1.0,
'index' : 'analyzed' ,
'store' : 'yes',
'type' : u'string',
"term_vector" : "with_positions_offsets"},
u'objectId' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'firstName' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'lastName' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'bcryptPassword' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'updatedAt' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'sessionToken' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'email' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'createdAt' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'summary' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'albums' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'headshot' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"}
u'profession' : {'boost': 1.0,
%pastebin 1-19
mapping = { u'username' : {'boost' : 1.0,
'index' : 'analyzed' ,
'store' : 'yes',
'type' : u'string',
"term_vector" : "with_positions_offsets"},
u'objectId' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'firstName' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'lastName' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'bcryptPassword' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'updatedAt' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'sessionToken' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'email' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'createdAt' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'summary' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'albums' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'headshot' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'profession' : {'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': u'string',
"term_vector" : "with_positions_offsets"},
u'pos': {'store': 'yes',
'type': u'integer'},
u'extra' : {'store': 'yes',
'type': u'integer'} }
mapping
conn.indices.put_mapping("_users", {'properties':mapping}, ["take_zero"])
conn.indices.put_mapping("users", {'properties':mapping}, ["take_zero"])
data
data['results']
data['results'][0]
data['results'][1]
for i in xrange(len(data['results'])):
try:
conn.index(data['results'][i])
except:
print i,' id problematic'
continue
conn.index(data['results'][i])
for i in xrange(len(data['results'])):
try:
conn.index(data['results'][i], "take_zero", "users", i+1)
except:
print i,' id problematic'
continue
conn.index(data['results'][i], "take_zero", "users", i+1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment