运用 makelogs 创建合适的 Elasticsearch 测试数据

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: 我们在使用 Elasticsearch 时,经常想找一些数据来进行测试,比如我们想试一下 Kibana 的可视化工具。我们有时想有很多的数据,但是有时就是找不到合适的数据。那么我们该怎么办呢?当然,我们有一种简单的办法就是使用 Kibana 给我们提供的测试数据,但是它可能也有很多的局限性:
文本作者:刘晓国,Elastic 公司社区布道师。新加坡国立大学硕士,西北工业大学硕士,曾就职于新加坡科技,康柏电脑,通用汽车,爱立信,诺基亚,Linaro,Ubuntu,Vantiq 等企业。

如果你想一站式快速体验 Elasticsearch 所有功能(包括 X-pack 付费功能),开通 阿里云 Elasticsearch 1核2G,即可首月免费试用。

image.png

另外一种方法就是使用一些工具来生成我们想要数量或要求的数据。在今天的文章中,我们就来介绍这样的一个工具 makelogs

下载 makelogs

我们在地址 https://github.com/elastic/makelogs 下载 makelogs:

git clone https://github.com/elastic/makelogs
cd makelogs

按照项目的要求,我们进行如下的安装:

npm install -g @elastic/makelogs

在实际使用中,我发现还需要安装另外的两个模块:

npm install update-notifier
npm install commander --save

这样我们的安装就完成了。

运行 makelogs

接下来,我们就可以运行 makelogs。为了能够了解这个工具的作用,我们使用如下的命令:

./bin/makelogs --help

$ ./bin/makelogs --help
Usage: makelogs [options]
 
A utility to generate sample log data.
 
Options:
  -c, --count <number>       Total event that will be created, accepts
                             expressions like "1m" for 1 million (b,m,t,h)
                             (default: 14000)
  -d, --days <number>        Number of days ± today to generate data for. Use
                             one number or two separated by a slash, e.g.
                             "1/10" to go back one day, and forward 10
                             (default: 1)
  --url <url>                Elasticsearch url, overrides host and auth, can
                             include any url part.
  -h, --host <host>          The host name and port (default:
                             "localhost:9200")
  --auth <auth>              user:password when you want to connect to a
                             secured elasticsearch cluster over basic auth
                             (default: null)
  --indexPrefix <name>       Name of the prefix of the index (default:
                             "logstash-")
  -s, --shards <number>      The number of primary shards (default: 1)
  -r, --replicas <number>    The number of replica shards (default: 0)
  --dry                      Test/Parse your arguments, but don't actually do
                             anything
  --reset                    Clear all {prefix}-* indices and the makelogs
                             index template before generating (default:
                             prompt)
  --no-reset                 Do not clear all {prefix}-* indices and the
                             makelogs index template before generating
                             (default: prompt)
  --verbose                  Log more info to the console
  --trace                    Log every request to elasticsearch, including
                             request bodies. BE CAREFUL!
  -o, --omit <...>           Omit a field from every event. See "formatting an
                             omit path"
  -i, --indexInterval <...>  The interval that indices should roll over,
                             either "daily", "monthly", "yearly", or a number
                             of documents. (default: 100000)
  --types                    Pass to enable types in index and document
                             creation
  --indexTemplatesV1         Pass to enable types in index templates v1
                             compatibility
  -V, --version              output the version number
  --help                     This help message
 
formatting an omit path
=======================
 
To remove a single top level property, you can simply specify the name of the property you want to remove:
 
  $ makelogs --omit request
 
To remove multiple properties, simply use omit multiple times
 
  $ makelogs --omit request --omit referrer
 
You can use dot notation to access properties of object values
 
  $ makelogs --omit machine.os
 
Or, you can omit the entire object value
 
  $ makelogs --omit machine
 
Finally, to traverse into arrays/nested fields you must use the [] operator
 
  $ makelogs --omit relatedContent[].title

上面显示了这个命令的所有的帮助信息。
接下来我们使用上面的命令来生成我们想要的 logstash 日志:

makelogs -c 10

等上面的命令运行完后,我们在 Kibana 里进行检查:

GET _cat/indices

image.png

我们看到一个新生成的叫做 logstash-0 的索引。我们使用如下的命令来检查文档的个数:

GET logstash-0/_count

image.png

上面显示共有 11 个文档生成。
我们可以对这个索引进行搜索:

我们可以看到这些被 makelogs 所生成的 logstash 文档。这些文档可以成为我们对数据分析的一个基础供我们进行练手。在生产环境中,当然不能进行使用了。

声明:本文由原文作者“ Elastic 中国社区布道师——刘晓国”授权转载,对未经许可擅自使用者,保留追究其法律责任的权利。

image.png

阿里云Elastic Stack】100%兼容开源ES,独有9大能力,提供免费 X-pack服务(单节点价值$6000)

相关活动


更多折扣活动,请访问阿里云 Elasticsearch 官网

阿里云 Elasticsearch 商业通用版,1核2G ,SSD 20G首月免费
阿里云 Logstash 2核4G首月免费
下载白皮书:Elasticsearch 八大经典场景应用


image.png

image.png

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
2月前
|
测试技术 API C#
C#使用Bogus生成测试数据
C#使用Bogus生成测试数据
39 1
|
1月前
|
存储 SQL 缓存
数据库测试|Elasticsearch和ClickHouse的对决
由于目前市场上主流的数据库有许多,这次我们选择其中一个比较典型的Elasticsearch来和ClickHouse做一次实战测试,让大家更直观地看到真实的比对数据,从而对这两个数据库有更深入的了解,也就能理解为什么我们会选择ClickHouse。
数据库测试|Elasticsearch和ClickHouse的对决
|
2月前
|
网络协议 Java API
SpringBoot整合Elasticsearch-Rest-Client、测试保存、复杂检索
这篇文章介绍了如何在SpringBoot中整合Elasticsearch-Rest-Client,并提供了保存数据和进行复杂检索的测试示例。
SpringBoot整合Elasticsearch-Rest-Client、测试保存、复杂检索
|
2月前
|
存储 缓存 监控
|
2月前
|
存储 人工智能 自然语言处理
知识库优化增强,支持多种数据类型、多种检索策略、召回测试 | Botnow上新
Botnow近期对其知识库功能进行了全面升级,显著提升了数据处理能力、检索效率及准确性。新版本支持多样化的数据格式,包括PDF、Word、TXT、Excel和CSV等文件,无需额外转换即可直接导入,极大地丰富了知识来源。此外,还新增了细致的文本分片管理和编辑功能,以及表格数据的结构化处理,使知识管理更为精细化。 同时,平台提供了多种检索策略,包括混合检索、语义检索和全文检索等,可根据具体需求灵活选择,有效解决了大模型幻觉问题,增强了专业领域的知识覆盖,从而显著提高了回复的准确性。这些改进广泛适用于客服咨询、知识问答等多种应用场景,极大提升了用户体验和交互质量。
58 4
|
18天前
|
存储 监控 安全
在自动化测试环境中,如何确保测试数据的安全性和隐私性
在自动化测试环境中,如何确保测试数据的安全性和隐私性
|
2月前
【Application Insights】使用Powershell命令向Application Insgihts发送测试数据
【Application Insights】使用Powershell命令向Application Insgihts发送测试数据
|
2月前
|
JSON Kubernetes Linux
【Application Insights】使用CURL命令向Application Insgihts发送测试数据
【Application Insights】使用CURL命令向Application Insgihts发送测试数据
|
2月前
|
自然语言处理 索引
ElasticSearch 实现分词全文检索 - 测试数据准备
ElasticSearch 实现分词全文检索 - 测试数据准备
46 1
|
2月前
|
关系型数据库 MySQL Python
[python]使用faker库生成测试数据
[python]使用faker库生成测试数据

相关产品

  • 检索分析服务 Elasticsearch版
  • 下一篇
    无影云桌面