I recently learned python, so I plan to use python to implement the data import and export tool. As I am a newbie, please forgive me for writing some imperfections in python 2.6, self-written, standby
'''Export and Import ElasticSearch Data. simple Example At _ main _ @ author: wgzh159@163.com @ note: uncheck consistency of data, please do it by self ''' import jsonimport osimport sysimport timeimport urllib2 reload (sys) sys. setdefaultencoding ('utf-8') # @ UndefinedVariable class exportEsData (): size = 10000 def _ init _ (self, url, index, type): self. url = url + "/" + index + "/" + type + "/_ search" self. index = index self. type = type def exportData (self): print ("export data begin... ") begin = time. time () try: OS. remove (self. index + "_" + self. type + ". json ") handle T: OS. mknod (self. index + "_" + self. type + ". json ") msg = urllib2.urlopen (self. url ). read () print (msg) obj = json. loads (msg) num = obj ["hits"] ["total"] start = 0 end = num/self. size + 1 while (start
The above is all the content of this article. I hope you will like it.