随机生成50个字段的elasticsearch的测试程序输入

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介:

词典位置: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,如需转载请自行联系原作者

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
2月前
|
PHP
Elasticsearch模糊查询单字段多字段
Elasticsearch模糊查询单字段多字段
19 0
|
3月前
|
Java API iOS开发
Elasticsearch 字段别名 field-alias
Elasticsearch 字段别名 field-alias
34 0
|
3月前
|
SQL 安全 测试技术
Web应用程序安全测试
Web应用程序安全测试
|
21天前
|
Linux Android开发
测试程序之提供ioctl函数应用操作GPIO适用于Linux/Android
测试程序之提供ioctl函数应用操作GPIO适用于Linux/Android
14 0
|
3天前
|
测试技术
LabVIEW程序测试
LabVIEW程序测试
|
5天前
|
搜索推荐 JavaScript Java
Elasticsearch 8.X 如何依据 Nested 嵌套类型的某个字段进行排序?
Elasticsearch 8.X 如何依据 Nested 嵌套类型的某个字段进行排序?
25 0
|
5天前
|
运维 测试技术 数据处理
Elasticsearch 优化查询中获取字段内容的方式,性能提升5倍!
Elasticsearch 优化查询中获取字段内容的方式,性能提升5倍!
15 0
|
5天前
|
JSON 测试技术 数据格式
Elasticsearch 8.X 如何生成 TB 级的测试数据 ?
Elasticsearch 8.X 如何生成 TB 级的测试数据 ?
13 0
|
6天前
|
数据可视化 Java 测试技术
JMeter 如何实现 Elasticsearch 8.X 性能测试?
JMeter 如何实现 Elasticsearch 8.X 性能测试?
13 0
|
6天前
|
数据采集 机器学习/深度学习 自然语言处理
Elasticsearch 8.X 如何动态的为正文添加摘要字段?
Elasticsearch 8.X 如何动态的为正文添加摘要字段?
10 0

热门文章

最新文章