【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 random
10 es = Elasticsearch()
11 
12 filePath = path.dirname(__file__)
13 
14 
15 # index1:wordcount
16 # stopwords
17 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 words
25 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] += 1
32                 
33 for key in wordDict.keys():
34     data = {'word':key , 'count':wordDict[key]}
35     es.index(index = 'wordcount' , doc_type = 'test' , body = data)
36     

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值