简体   繁体   中英

Are all data types strings in Neo4j accessed by py2neo through the REST API?

I have a query of this form creating a new node in neo4j:

cypher.get_or_create_indexed_node(index="person", key="name", value="Fred", properties={"level" : 1}

However, when I query Fred to inspect his properties, his level = "1" /with quotes/. It appears something is converting his value to a string. This wouldn't matter much---I could convert it on retrieval if necessary---except when I try to do cypher queries like...

start b = node:person("*:*") RETURN b.level, ID(b) ORDER BY b.level desc SKIP 5 LIMIT 5;

...I notice that b.level is not being ordered as expected. I'm seeing something like:

==> +-------------------------+
==> | b.level         | ID(b) |
==> +-------------------------+
==> | "3"             | 42    |
==> | "0"             | 53    |
==> | "2"             | 57    |
==> | "0"             | 63    |
==> | "2"             | 20    |
==> +-------------------------+

when I expect something like:

==> +-------------------------+
==> | b.level         | ID(b) |
==> +-------------------------+
==> | 3               | 42    |
==> | 2               | 20    |
==> | 2               | 57    |
==> | 0               | 63    |
==> | 0               | 53    |
==> +-------------------------+

I assume this is a data-type issue, since the reference manual shows skip/limit functionality.

Is it the case that all values are strings, or that there's something else I should add to input correctly?

This should not be the case, numeric properties are fully supported. I am also not able to recreate the scenario using the following test:

def test_get_or_create_indexed_node_with_int_property(self):
    graph_db = neo4j.GraphDatabaseService()
    fred = graph_db.get_or_create_indexed_node(index="person", key="name", value="Fred", properties={"level" : 1})
    assert isinstance(fred, neo4j.Node)
    assert fred["level"] == 1
    graph_db.delete(fred)

I notice that you have prefixed the get_or_create_indexed_node method with cypher - I would not expect this since the cypher module does not have such a method. I would instead expect it to be either something like graph_db or batch . Maybe this is a typo?

Maybe you could share some more of your surrounding code? Something else around it may be affecting your results.

Nige

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM