查看官方文档:Elasticsearch connector — Trino 395 Documentation
这段话的意思就是,elasticSearch支持很多时间类型的格式化方式,但是trino中es连接器只支持默认的date类型,就是不能加时间格式化
创建 yc_test_data 索引,索引中包含两个属性create_time 和 name
PUT http://10.226.21.38:9200/yc_test_data
{
"mappings": {
"properties": {
"create_time": {
"type": "date",
"format": "yyyy-MM-dd"
},
"name": {
"type": "keyword"
}
}
}
}
在索引中添加文档
POST http://10.226.21.38:9200/yc_test_data/_doc
{
"create_time":"2022-09-15",
"name":"a"
}
查看索引中的文档
GET http://10.226.21.38:9200/yc_test_data/_search
{
}
response:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "yc_test_data",
"_type": "_doc",
"_id": "gO12QIMBCEJMLwqlLGYV",
"_score": 1.0,
"_source": {
"create_time": "2022-09-15",
"name": "a"
}
}
]
}
}
用trino查询
注意看,带有格式化的时间字段create_time没有查询出来
如果索引yc_test_data的mapping改成这样,则用trino可以查询出来
{
"mappings": {
"properties": {
"create_time": {
"type": "date"
},
"name": {
"type": "keyword"
}
}
}
}
POST http://10.226.21.38:9200/yc_test_data/_doc
{
"create_time":"2022-09-15",
"name":"a"
}
{
"create_time":"2015-01-01T12:10:30Z",
"name":"b"
}
{
"create_time":"1663233358000",
"name":"c"
}
GET http://10.226.21.38:9200/yc_test_data/_search
{
"took": 279,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "yc_test_data",
"_type": "_doc",
"_id": "ue1_QIMBCEJMLwqlZGhW",
"_score": 1.0,
"_source": {
"create_time": "2022-09-15",
"name": "a"
}
},
{
"_index": "yc_test_data",
"_type": "_doc",
"_id": "7O2AQIMBCEJMLwqlPmgp",
"_score": 1.0,
"_source": {
"create_time": "2015-01-01T12:10:30Z",
"name": "b"
}
},
{
"_index": "yc_test_data",
"_type": "_doc",
"_id": "CO2AQIMBCEJMLwqlvGkA",
"_score": 1.0,
"_source": {
"create_time": "1663233358000",
"name": "c"
}
}
]
}
}
用trino查询:
文章来源地址https://www.toymoban.com/news/detail-562977.html文章来源:https://www.toymoban.com/news/detail-562977.html
到了这里,关于trino关于查询elasticSearch中时间字段的问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!