I am running on Neo4j (1.4) using Neo4j.rb gem (1.2.2) on Rails 3.1
I bumped into problem where neo4j index was corrupted that I cant run the database anymore, as mentioned in several forums like this I deleted the db/index dir and it worked. However I need to rebuild the index again.
I cou开发者_Python百科ld not find anywhere in the docs on how to rebuild the index, could anybody please help?
Thanks alot!
You should go into your database directory and remove
- Directory named index
- The file index.db
and later on traverse the hole set of nodes and edges, updating the properties of each node.
/purbon
My problem was similar - after upgrading to neo4j 1.5 (from 1.4) my indexes got corrupted. My case: I had two indexes:
__types__
: for indexing the type of persisted objects (provided byspring-data-neo4j 2.0.0.RC1
)User
: for indexing the username field, so I could do lookups after them
This resulted in a major problem, where I could find all the nodes by their id, but could not do lookups after username, or list all objects of a certain type.
The fix ( I will provide java code, but the idea would be the same in other languages too):
/* begin a transaction */
Transaction tx = graphDatabaseService.beginTx();
/* for all nodes in the database */
for (Node node : graphDatabaseService.getAllNodes()) {
/* reconstruct the saved object based on the __type__ property on the node - the result is a class that was annotated with @NodeEntity */
DefaultDbNode ddn = neo4jTemplate.createEntityFromStoredType(node,
null);
/* reindex this node, adding it to the __types__ index, with key "className" (it is used by spring-data-neo4j) with the value __type__ */
graphDatabaseService.index().forNodes("__types__")
.add(node, "className", node.getProperty("__type__"));
/* if the reconstructed object is a User object */
if (ddn instanceof User) {
/* add it to the User index, with the key "username" (which is also the saved fields name) */
graphDatabaseService.index().forNodes("User")
.add(node, "username", node.getProperty("username"));
}
}
/* end transaction */
tx.success();
tx.finish();
Hope this helps you or someone out!
Thanks to all who tried to help. In my case I have successfully solved the problem by taking the following steps:
Step 1 Following the recommendation from Neo4j's Michael Hunger (via mailing list), I used a tool called checkindex to remove corrupt index entries Lucene and Solr's Checkindex
Step 2 Upon removal of corrupt index entries, the remaining problem is to build them so Lucene can start querying them again. This could simply be done using using Model.addindex(:index_name). Note that this operation needs to be wrapped within a Neo4j::Transaction. In my case I ran it on railsconsole but I suppose you could also code them within the rails app.
Example:
Neo4j::Transaction.run do
User.all.each do |user|
user.add_index(:first_name)
user.add_index(:email)
user.save
end
end
Hope this could help others who face the same problems.
Cheers
精彩评论