ElasticSearch6.X版本自动添加时间戳

news/2024/7/3 5:38:39

需求:根据时间提取es数据
解决:为es的记录添加时间戳

1、方法

配置时间戳 pipeline

PUT _ingest/pipeline/my_timestamp_pipeline
{
  "description": "Adds a field to a document with the time of ingestion",
  "processors": [
    {
      "set": {
        "field": "@timestamp",
        "value": "{{_ingest.timestamp}}"
      }
    }
  ]
}

2、添加索引

#先创建索引
#语法:PUT /索引名
PUT /transactionmonitor-2021.12.15
{
    "settings": {
        "index": {
            "number_of_shards": 1,
            "number_of_replicas": 0
        }
    }
}

#在设置字段类型(es6.x版本)
#语法:PUT /索引库名/_mapping/类型名称
PUT /transactionmonitor-2021.12.15/_mapping/doc
{
    "properties": {
        "code": {
            "type": "text", 
            "fields": {
                "keyword": {
                    "type": "keyword"
                }
            }
        }, 
        "costTime": {
            "type": "long"
        }, 
        "endTime": {
            "type": "text", 
            "fields": {
                "keyword": {
                    "type": "keyword"
                }
            }
        }, 
        "host": {
            "type": "text", 
            "fields": {
                "keyword": {
                    "type": "keyword"
                }
            }
        }, 
        "isSuccess": {
            "type": "text", 
            "fields": {
                "keyword": {
                    "type": "keyword"
                }
            }
        }, 
        "isSyn": {
            "type": "text", 
            "fields": {
                "keyword": {
                    "type": "keyword"
                }
            }
        }, 
        "serviceName": {
            "type": "text", 
            "fields": {
                "keyword": {
                    "type": "keyword"
                }
            }
        }, 
        "startTime": {
            "type": "text", 
            "fields": {
                "keyword": {
                    "type": "keyword"
                }
            }
        }, 
        "transCode": {
            "type": "text", 
            "fields": {
                "keyword": {
                    "type": "keyword"
                }
            }
        }
    }
}

3、使用时间戳(添加数据)

POST /transactionmonitor-2021.12.15/doc?pipeline=my_timestamp_pipeline

POST /transactionmonitor-2021.12.15/doc?pipeline=my_timestamp_pipeline
{
    "msg": null, 
    "isSyn": "true", 
    "code": "0", 
    "serviceName": "wfservice",
    "costTime": 62, 
    "host": "127.0.0.1:8080", 
    "startTime": "2021-11-21 00:00:36.593", 
    "transCode": "GG02I023", 
    "endTime": "2021-11-21 00:00:36.655", 
    "isSuccess": "Y"
}

4、查询验证结果

GET /transactionmonitor-2021.12.15/doc/_search
{"query": {"match_all": {}}}

返回结果
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "transactionmonitor-2021.12.15",
        "_type": "doc",
        "_id": "gLEDvX0BdLj7MTacoc1Y",
        "_score": 1,
        "_source": {
          "msg": null,
          "isSyn": "true",
          "code": "0",
          "serviceName": "wfservice",
          "@timestamp": "2021-12-15T07:34:31.496Z",
          "costTime": 62,
          "host": "127.0.0.1:8080",
          "startTime": "2021-11-21 00:00:36.593",
          "transCode": "GG02I023",
          "endTime": "2021-11-21 00:00:36.655",
          "isSuccess": "Y"
        }
      }
    ]
  }
}

自动为数据添加上了@timestamp时间戳字段


http://www.niftyadmin.cn/n/4054445.html

相关文章

ElasticsearchTemplate替换为ElasticsearchRestTemplate(Transport Client替换为RestHighLevelClient)

在Elasticsearch 8.0的版本中也将完全移除TransportClient,其次有些es有些账号不能通过 9300端口连接 所以项目中打算由RestHighLevelClient 替换掉 Transport Client 版本 这里给一张springboot官方的版本推荐 这里我的springboot版本为 2.1.6.RELEASE Elasticse…

ruby编码说明

程序编码一般分几种情况: 1、源码文件编码 2、接收外部内容的编码 3、运行环境编码 4、操作系统编码 首先源码文件的编码,可以通过在ruby文件的头部添加一行申明即可,这样所有在源码里面出现的字符都保存为指定的编码: # -*- codi…

left join注意事项

一、【问题描述】 客户表(CLT.CSM_BASEINFO)左连接证件信息表(CLT.CSM_CERTINFO),通过客户名称查询客户信息。 1)证件信息表的字段筛选条件,放到on后面,查询结果正常 SELECT clt…

JDK8给Tomcat配置https

第一步:生成秘钥库 采用JDK自带的keytool工具生成秘钥 别名 xieh1234 存储路径 D:\cas\keystore\ keytool -genkey -v -alias xieh1234 -keyalg RSA -keystore D:\cas\keystore\xieh1234.keystore -alias 表示证书的别名,一个keystore文件中可以存放多…

笔记本插拔电源黑屏一下

亲爱的朋友你是否有这样的痛苦呢?当你的笔记本插上电源,屏幕要黑一下;当你拔掉电源时屏幕还是要黑一下。下面我就以Thinkpad E550电脑,win10系统为例和大家分享一下我的解决办法。 之所以会出现如上现状,是因为电脑插上电源和拔掉电源的刷屏率设置不相同。在桌面单击"右击…

编程游戏网站

http://www.imooc.com/article/14793转载于:https://blog.51cto.com/11283249/1950174

阿里云数加合作伙伴-袋鼠云获A轮融资,成立一年半获三轮投资超亿元

创投市场再次风起。2017年7月,袋鼠云宣布,获得来自戈壁创投主投、元璟资本跟投的A轮融资,相对于当前冷淡的投资市场,此举也再次引发了行业对大数据、云计算技术创新企业的关注。据袋鼠云CEO陈吉平(花名:拖雷…

Adam:大规模分布式机器学习框架

引子 转载请注明:http://blog.csdn.net/stdcoutzyx/article/details/46676515 又是好久没写博客,记得有一次看Ng大神的訪谈录,假设每周读三篇论文,那么经年以后,必定成为对某个领域非常熟悉的人。 可惜,在忙…