随机生成50个字段的elasticsearch的测试程序输入
词典位置:https://raw.githubusercontent.com/jonbcard/scrabble-bot/master/src/dictionary.txt
import json
from random import sample, randint
from uuid import uuid4 def 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 = 0
def 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] = word def 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()
随机生成50个字段的elasticsearch的测试程序输入的更多相关文章
- c#部分---网吧充值系统;简易的闹钟;出租车计费;简单计算器;对战游戏;等额本金法计算贷款还款利息等;随机生成10个不重复的50以内的整数;推箱子;
网吧充值系统namespace ConsoleApplication1 { class Program { struct huiyuan { public string name; public st ...
- Java随机生成18位身份证号
package com.ihome.data; import java.text.SimpleDateFormat; import java.util.Calendar; import java.ut ...
- Android锁定EditText内容和随机生成验证码
昨天写了个小Demo,实现了随机生成验证码,和锁定EditText两个小功能,先看一下效果图: 锁定EditText在我们不须要用户编辑EditText内容的时候能够用到,实现还是非常easy的,一行 ...
- shell随机生成身份证,姓名,电话,日期,分数,等级和insert语句
#!/bin/bash#生成随机身份证号,性别,年龄,电话,姓名,日期,分数和对应等级,并生成insert语句#作者AiYS,2018-02-06,转载请注明http://www.cnblogs.co ...
- PYTHON练习题 二. 使用random中的randint函数随机生成一个1~100之间的预设整数让用户键盘输入所猜的数。
Python 练习 标签: Python Python练习题 Python知识点 二. 使用random中的randint函数随机生成一个1~100之间的预设整数让用户键盘输入所猜的数,如果大于预设的 ...
- 随机生成气泡碰撞(原生js)
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>随 ...
- 随机生成四则运算式2-NEW+PSP项目计划(补充没有真分数的情况)
PS:这是昨天编写的随机生成四则运算式2的代码:http://www.cnblogs.com/wsqJohn/p/5264448.html 做了一些改进. 补:在上一次的运行中并没有加入真分数参与的运 ...
- roguelike地图的随机生成算法
如果要想自己设计一个roguelike游戏,那么需要你有一个随机地图生成,我在indienova上看到一篇文章,描述了一个roguelike算法,然后自己用unity实现了一个下. 原文地址:随机生成 ...
- js 随机生成信用卡号
本文实例讲述了JavaScript随机生成信用卡卡号的方法.分享给大家供大家参考.具体分析如下: 这段JS代码根据信用卡卡号产生规则随机生成信用卡卡号,是可以通过验证的,仅供学习参考,请不要用于非法用 ...
随机推荐
- HDU 4022 stl multiset
orz kss太腻害了. 一.set和multiset基础 set和multiset会根据特定的排序准则,自动将元素进行排序.不同的是后者允许元素重复而前者不允许. 需要包含头文件: #include ...
- 标准C程序设计七---10
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- Laravel 控制器的middleware中间件
场景:活动开始前只能访问宣传页面,开始后才可以访问其他页面: 步骤: 新建中间件, 注册中间件, 使用中间件, 中间件的前置和后置操作. 控制器: public function activity0( ...
- IOS开发之触摸背景关闭键盘的代码实现
直接上代码: // 触摸背景,关闭键盘 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch ...
- spring boot--常用配置
spring boot 需要引用的依赖项: spring-boot-starter-parent // 所有Spring Boot组件的基础引用 spring-boot-starter-web // ...
- [Inside HotSpot] Serial垃圾回收器 (二) Minor GC
Serial垃圾回收器Minor GC 1. DefNewGeneration垃圾回收 新生代使用复制算法做垃圾回收,比老年代的标记-压缩简单很多,所有回收代码都位于DefNewGeneration: ...
- python type()函数
我怎么把一个变量的类型写入文件?a = 3type(a)貌似返回的是type类型,不能打印,也不能用文件的write怎么半,或者怎么转换成srt之类的? type()函数得到的是一个类型而不是字符串, ...
- CODEVS_2144 砝码称重 2 折半搜索+二分查找+哈希
#include<iostream> #include<algorithm> #include<cstring> #include<map> #incl ...
- 未能加载文件或程序集“System.EnterpriseServices, Version=4.0.0.0或2.0.0.0
未能加载文件或程序集“System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50 ...
- Win10 - 默认图片查看器恢复
1. 新建一个文本文件“1.txt” 2. 在“1.txt”中添加如下代码,并保存: Windows Registry Editor Version 5.00 ; Change Extension's ...