首页 > 代码库 > 【ES】简单使用
【ES】简单使用
1 import sys 2 reload(sys) 3 sys.setdefaultencoding(‘utf-8‘) 4 5 from datetime import datetime 6 from elasticsearch import Elasticsearch 7 from os import path 8 import jieba 9 import random10 es = Elasticsearch()11 12 filePath = path.dirname(__file__)13 14 15 # index1:wordcount16 # stopwords17 stopWordFile = u‘stopwords.txt‘18 stopWordList = []19 for L in open(path.join(filePath , stopWordFile)).readlines():20 stopWordList.append(L.strip().decode(‘utf-8‘))21 stopWordList.extend([u‘腾讯‘,u‘视频‘ , u‘。‘])22 stopWordList = set(stopWordList)23 24 # information words25 new = ‘words.txt‘26 text = open(path.join( filePath , new )).read().strip(‘\r‘)27 wordDict = {}28 for w in jieba.cut(text):29 if w not in stopWordList:30 wordDict.setdefault(w , 0)31 wordDict[w] += 132 33 for key in wordDict.keys():34 data = http://www.mamicode.com/{‘word‘:key , ‘count‘:wordDict[key]}35 es.index(index = ‘wordcount‘ , doc_type = ‘test‘ , body = data)36
【ES】简单使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。