博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
随机生成50个字段的elasticsearch的测试程序输入
阅读量:6158 次
发布时间:2019-06-21

本文共 2245 字,大约阅读时间需要 7 分钟。

词典位置:https://raw.githubusercontent.com/jonbcard/scrabble-bot/master/src/dictionary.txt

 

import jsonfrom random import sample, randintfrom uuid import uuid4def gen_random_words():    with open("D:\\exp\\test_data\\dictionary.txt") as f:        words = [word.strip() for word in f]        f.close()        # print "OK. words length:", len(words)        return sample(words, 3000)    return []total_words = 0def sample_words(search_words, random_words):    global total_words    sample_cnt = 1000    for word in random_words:        total_words += 1        if len(search_words) < sample_cnt:            search_words.append(word)        else:            if randint(1, total_words) <= sample_cnt:                kick_off = randint(0, sample_cnt-1)                search_words[kick_off] = worddef gen_an_event(words, search_words):    event_data = {}    for i in range(50):        query_words = sample(words, randint(1, 10))        sample_words(search_words,query_words)        event_data["field-"+str(i)] = " ".join(query_words)    return {
"event": event_data, "sourcetype": "hec_test2"}if __name__ == "__main__": search_words = [] for i in range(500): words = gen_random_words() index_head = json.dumps({
"index" : { "_index" : "hec_test2", "_type" : "hec_type2" } }) es_out_put = "" splunk_out_put = "" for i in range(500): if i == 0: es_out_put += index_head + "\n" else: es_out_put += "\n" + index_head + "\n" event = gen_an_event(words, search_words) splunk_out_put += json.dumps(event) es_out_put += json.dumps(event["event"]) # print es_out_put # print splunk_out_put out_puts = [es_out_put, splunk_out_put] file_name = str(uuid4()) + ".json" for i,dir_name in enumerate(["ES", "Splunk"]): outfile = "D:\\test_data\\%s\\%s" % (dir_name, file_name) f = open(outfile, "w") f.write(out_puts[i]) f.close() print outfile outfile = "D:\\test_data\\search_words.txt" f = open(outfile, "w") f.write(json.dumps(search_words)) f.close()

 '

本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6599974.html,如需转载请自行联系原作者

你可能感兴趣的文章
execnet: rapid multi-Python deployment
查看>>
windows修改3389端口
查看>>
关于JavaScript词法
查看>>
FreeSwitch中的会议功能(4)
查看>>
MySQL中创建用户分配权限(到指定数据库或者指定数据库表中)
查看>>
AutoReleasePool 和 ARC 以及Garbage Collection
查看>>
重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础
查看>>
乐在其中设计模式(C#) - 提供者模式(Provider Pattern)
查看>>
MVP Community Camp 社区大课堂
查看>>
GWT用frame调用JSP
查看>>
大型高性能ASP.NET系统架构设计
查看>>
insert select带来的问题
查看>>
EasyUI 添加tab页(iframe方式)
查看>>
mysqldump主要参数探究
查看>>
好记心不如烂笔头,ssh登录 The authenticity of host 192.168.0.xxx can't be established. 的问题...
查看>>
使用addChildViewController手动控制UIViewController的切换
查看>>
Android Fragment应用实战
查看>>
SQL Server查询死锁并KILL
查看>>
内存或磁盘空间不足,Microsoft Office Excel 无法再次打开或保存任何文档。 [问题点数:20分,结帖人wenyang2004]...
查看>>
委托到Lambda的进化: ()=> {} 这个lambda表达式就是一个无参数的委托及具体方法的组合体。...
查看>>