python datax.py ../job/mysql2es.json -Dtime=2023-04-29 报错 datax.py: error: no such option: -D

动态 未结 0 82
小小草
小小草 LV1 2023年9月23日 23:40 发表
如果在执行datax命令时出现了"no such option: -D"的错误,可能是因为当前版本的datax不支持-D参数传递变量。 可以尝试使用其他方式来动态生成索引名称,例如: 1. 在json配置文件中,使用${}语法和函数来动态生成索引名称。例如: ``` { "job": { "content": [ { "reader": { "name": "mysqlreader", "parameter": { "username": "root", "password": "123456", "column": ["id", "name", "age"], "connection": [ { "jdbcUrl": "jdbc:mysql://localhost:3306/test", "table": ["user"] } ] } }, "writer": { "name": "elasticsearchwriter", "parameter": { "clusterName": "myCluster", "index": "${format('myIndex_%s', timeFormat(now(), 'yyyyMMdd'))}", "type": "myType", "nodes": [ {"ip": "192.168.0.1", "port": "9200"}, {"ip": "192.168.0.2", "port": "9200"}, {"ip": "192.168.0.3", "port": "9200"} ], "settings": { "number_of_shards": 6, "number_of_replicas": 1 } } } } ] } } ``` 在上述配置中,我们使用${format()}函数和timeFormat()函数来动态生成索引名称,其中now()表示当前时间,'yyyyMMdd'表示时间格式。 2. 在执行datax命令时,直接传递时间参数。例如: ``` python datax.py ../job/mysql2es.json time=2023-04-29 ``` 在执行过程中,datax会将索引名称设置为myIndex_20230429,并将数据写入到该索引中。 注意:如果使用第二种方式传递时间参数,需要在json配置文件中使用${time}来引用该变量。例如: ``` { "job
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复