1、先下载测试文件,然后新建索引(数据库)
数据库1 莎士比亚作品全集
curl -H "Content-Type: application/json" -XPUT http://localhost:9200/shakespeare -d'
{
"mappings": {
"doc": {
"properties": {
"speaker": {"type": "keyword"},
"play_name": {"type": "keyword"},
"line_id": {"type": "integer"},
"speech_number": {"type": "integer"}
}
}
}
}
';
数据库2 经度/纬度地理位置
curl -H "Content-Type: application/json" -XPUT http://localhost:9200/logstash-2015.05.18 -d'
{
"mappings": {
"log": {
"properties": {
"geo": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
}
}
}
}
';
curl -H "Content-Type: application/json" -XPUT http://localhost:9200/logstash-2015.05.19 -d'
{
"mappings": {
"log": {
"properties": {
"geo": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
}
}
}
}
';
curl -H "Content-Type: application/json" -XPUT http://localhost:9200/logstash-2015.05.20 -d'
{
"mappings": {
"log": {
"properties": {
"geo": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
}
}
}
}
';
账户数据集不需要创建索引映射 :
2、批量导入数据,用Elasticsearch的 bulk API 来加载数据集,命令如下
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary @accounts.json
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/shakespeare/doc/_bulk?pretty' --data-binary @shakespeare_6.0.json
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/_bulk?pretty' --data-binary @logs.jsonl
很疑惑为什么导入logstash的三个数据库没有指定索引名,看了下logs.jsonl,原来是在文件中写明的。
以上为ES的操作和Kibana没有关系,下面看kibana
3、定义自己关注的索引
单击 Management 选项,然后单击 Index Patterns 选项。点击 Add New 定义一个新的索引模式。带时间戳索引的指定时间戳字段。
4、探索数据
当前索引模式显示在查询栏下面。索引模式决定了当您提交查询时搜索哪些索引
您可以把您感兴趣的字段名称和值当做搜索的条件,对于数字字段您可以使用比较运算符,例如大于(>)、小于(<)或等于(=)。您可以使用逻辑运算符 AND,OR 和 NOT 连接搜索条件,这些运算符需要全部大写。
尝试选择 ba* (对应bank) 索引模式并在查询栏中输入以下字符串:
account_number:<100 AND balance:>47500
此查询返回0到99之间所有余额超过47,500的账户号码。搜索银行样本数据时,它返回5个结果:帐户号码8,32,78,85和97。
查询语法就是指明查询条件,用于过滤数据用的。
单纯的数据一个字符串,表明在当前索引的所有字段中,搜索包含当前字符串的记录:
如果要指定在某个字段中搜索,则使用filedname:searchtext的格式:
这样查询到一条数据,也可以使用区间,格式为filedname:[start TO end],如下面的语法就查询到10条数据。
也可以使用逻辑表达式并且可以带上括号,表达式符号为AND OR NOT。
表明在1000行内,有12行中包含love。
5、可视化
界面操作较多,参见:
参见https://www.elastic.co/guide/cn/kibana/current/tutorial-visualizing.html#tutorial-visualizing