JDBC、Elasticsearch 和 Postgresql Json 数据类型

3
  • PostgreSQL: 9.3.2
    • Elasticsearch: 0.90
    • jprante/elasticsearch-river-jdbc: 2.2.2
    • PostgreSQL JDBC: 9.3-1100 JDBC 41

我正在尝试使用elasticsearch river将postgresql的Json数据类型列导入elasticsearch。

这里是创建的river:

curl -XPUT 'localhost:9200/_river/business_river/_meta' -d '{
          "type" : "jdbc",
          "jdbc" : {
              "driver" : "org.postgresql.Driver",
              "url" : "jdbc:postgresql://localhost:5432/business",
              "user" : "postgres",
              "password" : "",
              "sql" : "select id, active, companies->'sic'->>'national_number' AS sic, companies->'names'->>'name' AS name, companies->'address'->>'country' AS country from businesses.business",
              "index" : "business",
              "type" : "jdbc"
     }
}'

这条河抱怨说“names”列不存在!!!在Postgresql中查询是有效的,这让我想到JDBC或这条河还不支持Json数据类型。

以下是完整的信息:

[2014-01-13 07:47:27,919][INFO ][org.xbib.elasticsearch.river.jdbc.JDBCRiver] [Brigade] [jdbc][business_river] starting JDBC river: URL [jdbc:postgresql://localhost:5432/business], driver [org.postgresql.Driver], strategy [oneshot], index [jdbc]/[jdbc]
[2014-01-13 07:47:33,281][ERROR][org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverFlow] ERROR: column "names" does not exist
  Position: 31
org.postgresql.util.PSQLException: ERROR: column "names" does not exist
  Position: 31
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)                                                                                         
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:560)                                                                                 
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:403)                                                                        
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:283)                                                                            
        at org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverSource.executeQuery(SimpleRiverSource.java:417)                                                         
        at org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverSource.fetch(SimpleRiverSource.java:241)                                                                
        at org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverFlow.move(SimpleRiverFlow.java:184)                                                                     
        at org.xbib.elasticsearch.river.jdbc.strategy.oneshot.OneShotRiverFlow.run(OneShotRiverFlow.java:38)                                                                    
        at java.lang.Thread.run(Thread.java:744)

显示:从PostgreSQL日志文件中显示确切的错误消息和产生该错误的后端SQL。此外,我不认为这是原因,但您的引用方式是错误的。看看SO如何对您的curl输入进行语法突出显示。看到companies->'sic'了吗?好吧,sic是未引用的文本。由于没有shell元字符,所以这并不重要。 - Craig Ringer
请在答案区编写解决方案并进行检查,以便被视为已回答。 - eliasah
@sdeschamps - 请将您的解决方案编辑移动到答案中并标记为已接受。 - Andy
请注意,自 Elasticsearch v1.5 开始,Rivers 已被弃用,并将在2.0中完全删除。 - Damian
1个回答

1
感谢Craig Ringer指出真正的问题,我重新编写了我的代码,用"\u0027"替换了postgresql json查询中的简单引号,现在它可以正常工作了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接