Cypher REST查询中的索引参数化

时间:2013-05-23 14:53:37

标签: rest lucene neo4j cypher

我有这个查询,它运行良好但索引中没有参数化。 emp是一个索引,NUM_OFC_CA是一个emp号(emp索引中的键),以简化我想返回NME_CA。

curl -X POST http://xyzhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query -H "Content-Type: application/json" --data-binary '{
    "query": "START ca=node:emp(\"NUM_OFC_CA: 997015\") RETURN distinct ca.NME_CA as `CA Name`",
    "params": {
     }
}'

我如何参数化上面的REST查询,我尝试过这样的事情:

curl -X POST http://xyzhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query -H "Content-Type: application/json" --data-binary '{
    "query": "START ca=node:emp(\"NUM_OFC_CA: {num_ofc_ca}\") RETURN distinct ca.NME_CA as `CAName`",
    "params": {
        "num_ofc_ca": "997015"
    }
}'

我收到此错误:

{
  "message" : "org.apache.lucene.queryParser.ParseException: Cannot parse 'NUM_OFC_CA: {num_ofc_ca}': Encountered \" \"}\" \"} \"\" at line 1, column 23.\nWas expecting one of:\n    \"TO\" ...\n    <RANGEEX_QUOTED> ...\n    <RANGEEX_GOOP> ...\n    ",
  "exception" : "BadInputException",
  "stacktrace" : [ "org.neo4j.server.plugin.cypher.CypherPlugin.executeScript(CypherPlugin.java:61)", "java.lang.reflect.Method.invoke(Method.java:597)", "org.neo4j.server.plugins.PluginMethod.invoke(PluginMethod.java:57)", "org.neo4j.server.plugins.PluginManager.invoke(PluginManager.java:168)", "org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension(ExtensionService.java:300)", "org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension(ExtensionService.java:122)", "java.lang.reflect.Method.invoke(Method.java:597)" ]
}

需要帮助才能解决此问题。 谢谢!

1 个答案:

答案 0 :(得分:3)

如果您需要普通索引查询,syntax如下:

curl -X POST http://<host>:7474/db/data/ext/CypherPlugin/graphdb/execute_query -H "Content-Type: application/json" --databinary '{
    "query": ca=node:emp(NUM_OFC_CA = {num_ofc_ca}) RETURN distinct ca.NME_CA as `CAName`",
    "params": {
        "num_ofc_ca": "997015"
    }
}'

对于一般lucene index query,您需要参数化完整查询:

curl -X POST http://<host>:7474/db/data/ext/CypherPlugin/graphdb/execute_query -H "Content-Type: application/json" --databinary '{
    "query": ca=node:emp({num_ofc_ca_query}) RETURN distinct ca.NME_CA as `CAName`",
    "params": {
        "num_ofc_ca_query": "NUM_OFC_CA:997015"
    }
}'