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

本文共 2162 字,大约阅读时间需要 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()

 

转载地址:http://zvjca.baihongyu.com/

你可能感兴趣的文章
[转载]你所不了解的DevOps
查看>>
关于双十二崩盘的一些思考
查看>>
centos7 开启端口防火墙配置(如开启3306或者80端口)
查看>>
async/await使用深入详解
查看>>
uemacs快捷键
查看>>
ASP.NET编程模型:RegisterStartupScript向页面注册脚本
查看>>
LPC21O3第一课:第一个实验,LED灯闪烁及ADS1.2的初步使用
查看>>
matlab练习程序(共生矩阵)
查看>>
BizTalk Server 2006 R3 is Announced
查看>>
[译]C# Socket连接请求超时机制
查看>>
fileAs访问拒绝and net后台打开服务器端文件和关闭服务器端文件
查看>>
POJ 3020 Antenna Placement
查看>>
POJ 1486 Sorting Slides (KM)
查看>>
解决 NDP40-KB2468871不能安装
查看>>
《数据结构与算法分析》学习笔记(三)——链表ADT
查看>>
通信原理实践(三)——FM调制
查看>>
mysql 学习总结
查看>>
Hadoop--有关Hadoop的启动
查看>>
[Leetcode] Search a 2D Matrix
查看>>
(转)浅谈分布式
查看>>