问题描述:

SOLVED

OK, I just messed with neo4j-server.properties` config file, I shouldn't have written the db path using "...".

I have created a neo4j database using java's inserter and I strive to access it with py2neo. Here's my java code:

///opt/java/64/jdk1.6.0_45/bin/javac -classpath $HOME/opt/usr/neo4j-community-1.8.2/lib/*:. neo_batch.java

///opt/java/64/jdk1.6.0_45/bin/java -classpath $HOME/opt/usr/neo4j-community-1.8.2/lib/*:. neo_batch

import org.neo4j.graphdb.GraphDatabaseService;

import org.neo4j.graphdb.Node;

import org.neo4j.graphdb.Transaction;

import org.neo4j.graphdb.factory.GraphDatabaseFactory;

import org.neo4j.graphdb.index.Index;

import java.io.File;

import java.io.IOException;

import java.io.InputStream;

import java.io.Writer;

import java.util.HashMap;

import java.util.Map;

import java.lang.Long;

import org.neo4j.graphdb.Direction;

import org.neo4j.graphdb.DynamicRelationshipType;

import org.neo4j.graphdb.GraphDatabaseService;

import org.neo4j.graphdb.Node;

import org.neo4j.graphdb.RelationshipType;

import org.neo4j.helpers.collection.MapUtil;

import org.neo4j.unsafe.batchinsert.BatchInserter;

import org.neo4j.unsafe.batchinsert.BatchInserterImpl;

import org.neo4j.unsafe.batchinsert.BatchInserters;

import org.neo4j.unsafe.batchinsert.BatchInserterIndex;

import org.neo4j.unsafe.batchinsert.BatchInserterIndexProvider;

import org.neo4j.unsafe.batchinsert.LuceneBatchInserterIndexProvider;

public class neo_batch{

private static final String KEY = "id";

public static void main(String[] args) {

//create & connect 2 neo db folder

String batch_dir = "neo4j-batchinserter-store";

BatchInserter inserter = BatchInserters.inserter( batch_dir );

//set up neo index

BatchInserterIndexProvider indexProvider =

new LuceneBatchInserterIndexProvider( inserter );

BatchInserterIndex OneIndex =

indexProvider.nodeIndex( "one", MapUtil.stringMap( "type", "exact" ) );

OneIndex.setCacheCapacity( "id", 100000 );

//batchin graph, index and relationships

RelationshipType linked = DynamicRelationshipType.withName( "linked" );

for (int i=0;i<10;i++){

System.out.println(i);

long Node1 = createIndexedNode(inserter, OneIndex, i);

long Node2 = createIndexedNode(inserter, OneIndex, i+10);

inserter.createRelationship(Node1, Node2, linked, null);

}

indexProvider.shutdown();

inserter.shutdown();

}

// START SNIPPET: helperMethods

private static long createIndexedNode(BatchInserter inserter,BatchInserterIndex OneIndex,final long id)

{

Map<String, Object> properties = new HashMap<String, Object>();

properties.put( KEY, id );

long node = inserter.createNode( properties );

OneIndex.add( node, properties);

return node;

}

// END SNIPPET: helperMethods

}

Then I modify the neo4j-server.properties config file accordingly and start neo4j start.

The following python code suggests the graph is empty

from py2neo import neo4j

graph = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")

graph.size()

Out[8]: 0

graph.get_indexed_node("one",'id',1)

What's wrong with my appraoch? Thanks

EDIT

Neither can I count the nodes with a cypher:

neo4j-sh (?)$ START n=node(*)

> return count(*);

+----------+

| count(*) |

+----------+

| 0 |

+----------+

1 row

0 ms

EDIT 2

I can check with the java api that the indexes and nodes exist

private static void query_batched_db(){

GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( batch_dir);

IndexManager indexes = graphDb.index();

boolean oneExists = indexes.existsForNodes("one");

System.out.println("Does the 'one' index exists: "+oneExists);

System.out.println("list indexes: "+graphDb.index().nodeIndexNames());

//search index 'one'

Index<Node> oneIndex = graphDb.index().forNodes( "one" );

for (int i=0;i<25;i++){

IndexHits<Node> hits = oneIndex.get( KEY, i );

System.out.println(hits.size());

}

graphDb.shutdown();

}

Where the output is

Does the 'one' index exists: true

list indexes: [Ljava.lang.String;@26ae533a

1

1

...

1

1

Now if I populate the graph using python, I won't be able to access them with the previous java method (will count 20 again)

from py2neo import neo4j

graph = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")

idx=graph.get_or_create_index(neo4j.Node,"idx")

for k in range(100):

graph.get_or_create_indexed_node('idx','id',k,{'id':k}

EDIT 3

Now I delete the store I created with the batchinserter, namely neo4j-test-store while the neo4j-server.properties config file continues to point to the deleted store, namely org.neo4j.server.database.location="{some_path}/neo4j-test-store".

Now if I run a cypher count, I got a 100, 100 being the number of nodes I inserted using py2neo.

I am going crazy with this stuff!

SOLVED

OK, I just messed with neo4j-server.properties` config file, I shouldn't have written the db path using "...".

相关阅读:
Top