指标参数在Cypher支架REST查询(Index parameterization in Cyph

2019-10-18 04:22发布

我有这个疑问这在指数运行良好,但没有参数化。 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)" ]
}

需要帮助解决这个问题。 谢谢!

Answer 1:

如果你需要一个简单的索引查询的语法如下:

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索引查询 ,则需要参数化的完整的查询:

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"
    }
}'


文章来源: Index parameterization in Cypher REST query