1

我有一个 Postgresql 9.1 表,其中包括“city”、“admin1”和“country”列。我想选择输出格式为“city, admin1, country”的唯一值。

我可能有多个纽约和明尼苏达州罗切斯特的参赛作品,但我只想要一个。这是为了填充弹性搜索索引,我正在使用JDBC River 插件

以下 SELECT 在 PGAdmin3 的 SQL 编辑器中执行我想要的操作:

SELECT city || ', ' || admin1 || ', ' || country AS city FROM table GROUP BY city, admin1, country;

但在以下失败

curl -XPUT 'localhost:9200/_river/nibbel_river/_meta' -d '{

           "type" : "jdbc",
           "jdbc" : {
               "driver" : "org.postgresql.Driver",
               "url" : "jdbc:postgresql://localhost:5432/table",
               "user" : "",
               "password" : "",
           "sql" : "SELECT city || ', ' || admin1 || ', ' || country AS city FROM everything GROUP BY city, admin1, country",
           "poll" : "7d"
           },
           "index" : {
               "index" : "city",
               "type" : "everything"
           }
       }'

有错误

curl: (6) Couldn't resolve host ' || admin1 || ,'
curl: (3) [globbing] unmatched close brace/bracket at pos 102
{"error":"MapperParsingException[Failed to parse [jdbc.sql]]; nested: JsonParseException[Unexpected end-of-input in VALUE_STRING\n at [Source: [B@1192b0c; line: 8, column: 565]]; ","status":400}

这个的语法是什么?

4

1 回答 1

5

查询中的所有撇号都必须像这样转义:'\''例如:

curl -XPUT 'localhost:9200/_river/nibbel_river/_meta' -d '{
    "type" : "jdbc",
    "jdbc" : {
        "driver" : "org.postgresql.Driver",
        "url" : "jdbc:postgresql://localhost:5432/table",
        "user" : "",
        "password" : "",
        "sql" : "SELECT city || '\'', '\'' || admin1 || '\'', '\'' || country AS city FROM everything GROUP BY city, admin1, country",
        "poll" : "7d"
    },
    "index" : {
        "index" : "city",
        "type" : "everything"
    }
}'
于 2012-11-19T10:41:19.150 回答