elasticsearch-jdbc icon indicating copy to clipboard operation
elasticsearch-jdbc copied to clipboard

Reproducing the nested example from the documentation

Open tinoater opened this issue 9 years ago • 0 comments

Hi,

I'm trying to create a nested JSON using jdbc, but I cannot replicate the example from the docs:

CREATE TABLE blog (name VARCHAR(100), published DATE);
CREATE TABLE attachment (id INT, blog_id INT, name VARCHAR(100));


INSERT INTO blog VALUES (4679, 'Joe', DATE(NOW()));
INSERT INTO attachment VALUES (9450, 4679, '/web/q/g/h/57436356.jpg');
INSERT INTO attachment VALUES (9465, 4679, '/web/i/s/q/GS3193626.jpg');
INSERT INTO attachment VALUES (9451, 4679, '/web/i/s/q/GS3193626.jpg');


SELECT b.id AS '_id'
     , b.name AS 'blog.name'
     , b.published AS 'blog.published'
     , a.id AS 'blog.attachment[id]'
     , a.name AS 'blog.attachment[name]'
  FROM blog b
  JOIN attachment a
    ON b.id = a.blog_id
;

Gives a result of:

{
"_id":4679, "blog.name":"Joe", "blog.published":"2016-09-29", "blog.attachment[id]":9450, "blog.attachment[name]":"/web/q/g/h/57436356.jpg", "@version":"1", "@timestamp":"2016-09-29T16:23:59.592Z" }{
"_id":4679, "blog.name":"Joe", "blog.published":"2016-09-29", "blog.attachment[id]":9465, "blog.attachment[name]":"/web/i/s/q/GS3193626.jpg", "@version":"1", "@timestamp":"2016-09-29T16:23:59.593Z" }{
"_id":4679, "blog.name":"Joe", "blog.published":"2016-09-29", "blog.attachment[id]":9451, "blog.attachment[name]":"/web/i/s/q/GS3193626.jpg", "@version":"1", "@timestamp":"2016-09-29T16:23:59.593Z" }

Where the JSON is not nested, and actually is missing separating commas... Please could someone provide the full example from the documentation for me to work with?

Using: jdbc_driver_library => "/home/bobby/Desktop/elasticsearch-jdbc-2.3.4.0/lib/mysql-connector-java-5.1.38.jar"

tinoater avatar Sep 29 '16 16:09 tinoater