Мы попробовали следующий код и хотим, чтобы тип был ключевым словом:
Код: Выделить всё
pipeline.apply("Read MySQL data", JdbcIO.
read().withDataSourceConfiguration(config)
.withQuery(sql).withOutputParallelization(false)
.withFetchSize(readBatchSize)
.withRowMapper(new JdbcIO.RowMapper() {
private static final long serialVersionUID = 1L;
public ProgramProduct mapRow(ResultSet resultSet) throws Exception {
return new ProgramProduct(resultSet.getInt("product_fk"), resultSet.getInt("program_fk"),
resultSet.getString("type"),
getProductConfig(resultSet.getDouble("price"),
resultSet.getDouble("variable_min_points"),
resultSet.getDouble("variable_max_points")),
resultSet.getString("date_created"));
}
})).apply("Apply transform on data", ParDo.of(new DoFn() {
private static final long serialVersionUID = 1L;
@ProcessElement
public void processElement(ProcessContext processContext) throws SQLException {
ProgramProduct product = processContext.element();
String jsonObject;
if (null != product) {
jsonObject = new GsonBuilder().create().toJson(product);
processContext.output(jsonObject.toString());
} else {
processContext.output(null);
}
}
}))
.apply("Write to Elasticsearch", ElasticsearchIO.write()
.withConnectionConfiguration(ElasticsearchIO.ConnectionConfiguration
.create(new String[] { elasticHost }, elasticIndexName)
.withApiKey(elasticApiKey))
.withMaxBatchSize(elasticBatchSize));
Подробнее здесь: https://stackoverflow.com/questions/787 ... icsearchio