随机生成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()
复制代码

 '














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

相关实践学习
以电商场景为例搭建AI语义搜索应用
本实验旨在通过阿里云Elasticsearch结合阿里云搜索开发工作台AI模型服务,构建一个高效、精准的语义搜索系统,模拟电商场景,深入理解AI搜索技术原理并掌握其实现过程。
ElasticSearch 最新快速入门教程
本课程由千锋教育提供。全文搜索的需求非常大。而开源的解决办法Elasricsearch(Elastic)就是一个非常好的工具。目前是全文搜索引擎的首选。本系列教程由浅入深讲解了在CentOS7系统下如何搭建ElasticSearch,如何使用Kibana实现各种方式的搜索并详细分析了搜索的原理,最后讲解了在Java应用中如何集成ElasticSearch并实现搜索。 &nbsp;
相关文章
|
安全 JavaScript 前端开发
AppSpider 7.5.020 发布 - Web 应用程序安全测试
AppSpider 7.5.020 for Windows - Web 应用程序安全测试
129 0
|
5月前
|
Java 测试技术 数据安全/隐私保护
通过yaml文件配置自动化测试程序
通过yaml文件可以将自动化测试环境,测试数据和测试行为分开,请看一下案例
153 4
|
9月前
|
监控 安全 测试技术
【01】卓伊凡收到冒充税务机关的诈骗程序-决定在沙盒Sandbox环境中运行测试下-广大企业同胞们注意防诈骗
【01】卓伊凡收到冒充税务机关的诈骗程序-决定在沙盒Sandbox环境中运行测试下-广大企业同胞们注意防诈骗
242 14
【01】卓伊凡收到冒充税务机关的诈骗程序-决定在沙盒Sandbox环境中运行测试下-广大企业同胞们注意防诈骗
|
10月前
|
安全 测试技术 Linux
Acunetix v25.4 发布 - Web 应用程序安全测试
Acunetix v25.4 (Linux, Windows) - Web 应用程序安全测试
306 3
Acunetix v25.4 发布 - Web 应用程序安全测试
|
9月前
|
安全 Devops 测试技术
AppSpider 7.5.018 for Windows - Web 应用程序安全测试
AppSpider 7.5.018 for Windows - Web 应用程序安全测试
186 0
AppSpider 7.5.018 for Windows - Web 应用程序安全测试
|
12月前
|
安全 JavaScript Java
AppSpider Pro 7.5.015 for Windows - Web 应用程序安全测试
AppSpider Pro 7.5.015 for Windows - Web 应用程序安全测试
204 12
AppSpider Pro 7.5.015 for Windows - Web 应用程序安全测试
|
11月前
|
自然语言处理 安全 测试技术
HCL AppScan Standard 10.8.0 (Windows) - Web 应用程序安全测试
HCL AppScan Standard 10.8.0 (Windows) - Web 应用程序安全测试
743 0
HCL AppScan Standard 10.8.0 (Windows) - Web 应用程序安全测试
|
算法 Java 测试技术
Benchmark.NET:让 C# 测试程序性能变得既酷又简单
Benchmark.NET是一款专为 .NET 平台设计的性能基准测试框架,它可以帮助你测量代码的执行时间、内存使用情况等性能指标。它就像是你代码的 "健身教练",帮助你找到瓶颈,优化性能,让你的应用跑得更快、更稳!希望这个小教程能让你在追求高性能的路上越走越远,享受编程带来的无限乐趣!
788 13
|
并行计算 算法 测试技术
C语言因高效灵活被广泛应用于软件开发。本文探讨了优化C语言程序性能的策略,涵盖算法优化、代码结构优化、内存管理优化、编译器优化、数据结构优化、并行计算优化及性能测试与分析七个方面
C语言因高效灵活被广泛应用于软件开发。本文探讨了优化C语言程序性能的策略,涵盖算法优化、代码结构优化、内存管理优化、编译器优化、数据结构优化、并行计算优化及性能测试与分析七个方面,旨在通过综合策略提升程序性能,满足实际需求。
516 1
|
存储 SQL 缓存
数据库测试|Elasticsearch和ClickHouse的对决
由于目前市场上主流的数据库有许多,这次我们选择其中一个比较典型的Elasticsearch来和ClickHouse做一次实战测试,让大家更直观地看到真实的比对数据,从而对这两个数据库有更深入的了解,也就能理解为什么我们会选择ClickHouse。
数据库测试|Elasticsearch和ClickHouse的对决

热门文章

最新文章