Skip to content

mysql时间字符串(varchar "2018-11-20 10:10:10")支持转为ES的date类型 #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Although there are some other MySQL rivers for Elasticsearch, like [elasticsearc
## Todo

+ MySQL 8
+ ES 6
+ ES 6 (After verification (version 6.4.2), it is now supported. Delete and update are supported)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Em, are you sure we can support ES 6 directly? Seem ES 6 has already removed doc Type?

+ Statistic.

## Donate
Expand Down
2 changes: 2 additions & 0 deletions etc/river.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ id="es_id"
tags="es_tags,list"
# Map column `keywords` to ES with array type
keywords=",list"
# Map column (mysql type varchar(255) "2018-11-20 10:10:10") `time` to ES with date type
time="time,date"

# Filter rule
#
Expand Down
9 changes: 9 additions & 0 deletions river/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,15 @@ func (r *River) getFieldValue(col *schema.TableColumn, fieldType string, value i
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
fieldValue = r.makeReqColumnData(col, time.Unix(v.Int(), 0).Format(mysql.TimeFormat))
}
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use else if col.Type == schema.TYPE_STRING

if col.Type == schema.TYPE_STRING {
col.Type = schema.TYPE_DATETIME
v := r.makeReqColumnData(col, value)
str, _ := v.(string)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch v.(type) {
    case string:
    case []byte:
    default:
}

I think you can check string and []byte here.

stamp, _ := time.ParseInLocation("2006-01-02 03:04:05", str, time.Local)
t := int64(stamp.Unix())
fieldValue = r.makeReqColumnData(col, time.Unix(t, 0).Format(mysql.TimeFormat))
}
}
}

Expand Down