Re: [Neo4j] Using SET then updating the index

76 views
Skip to first unread message

Michael Hunger

unread,
Sep 20, 2012, 3:35:38 PM9/20/12
to ne...@googlegroups.com
The @Indexed annotation in SDN only integrates with your objects not with raw cypher usage.

so the index is updated if you do:

MyNode node template.lookup("name","Steve Tyler").to(MyNode.class).getSingle()
node.setName("Michael");
template.save(node);

If you use raw cypher for updates you have to index the nodes yourself using the Neo4j Template.

Michael

Am 20.09.2012 um 20:32 schrieb Michael Janiak:

Hi there,

How do I go about updating the index after using the SET command?

For example, I have some nodes:

@NodeEntity
public class MyNode{
 
@Indexed(indexType=IndexType.FULLTEXT, indexName="name")
 
private String name;
}

Within cypher I can find a node by index like so:

START n=node:name(name="Steve Tyler") RETURN n

However, when I use the SET command to change the name parameter

START n=node:name(name="Steve Tyler")
SET n.name ="Michael"
RETURN n

The name has been changed to "Michael" but I cannot find the node by "Michael", I can only find it by "Steve Tyler". So this still works:
START n=node:name(name="Steve Tyler") RETURN n
But this doesn't

START n=node:name(name="Michael") RETURN n

This is also a problem when creating new nodes, they don't get added to the index.

Any thoughts would be welcome and thank you in advance!

Michael









--
 
 

Michael Janiak

unread,
Sep 20, 2012, 7:09:40 PM9/20/12
to ne...@googlegroups.com
Ok thank you.

How do I go about indexing the nodes using neo4j template?

At the moment, I'll create a node as described below, load it up with properties then save it using a repository. Should I be adding a step after the save?

If I have several indexes I could see this getting slow especially since I'm doing it over rest.

@Autowired Repository repository;
@Autowired Neo4jTemplate template;

public MyNode addNode(String foo){
   
MyNode node = new MyNode();
   node
.setName(foo) etc

   repository
.save(node);
   
template.index("name", node, "name",  foo);
}

Michael

Michael Hunger

unread,
Sep 20, 2012, 7:39:17 PM9/20/12
to ne...@googlegroups.com
SDN is right now not optimal for going over REST, at least if you have lots of updating operations.

If you use your annotated domain objects you don't have to use manual indexing, just when you create or update nodes via cypher.

Michael

--
 
 

Michael Janiak

unread,
Sep 21, 2012, 7:58:47 AM9/21/12
to ne...@googlegroups.com
That's very interesting, thank you for that, I'll do that. To be honest I'd prefer to use an embedded database but not sure how to do that on Heroku at the moment.

Sorry to bother you but one more related question. We're looking to incorporate Neo4j Spatial in our project and from what I understand of spatial, in addition to a normal node layer, you add another layer of spatial nodes that you extend a relationship to.

I'm guessing the process would look like, check if there's a node at your required location and if there isn't create it and build a relationship to it. Since Spatial nodes have a WKT indexType = Point, does that mean if you create a new node in cypher, you should go back to the template and define the index?

Michael Hunger

unread,
Sep 21, 2012, 8:11:30 AM9/21/12
to ne...@googlegroups.com
Right now the spatial index entry is created when you "add" node with a WKT value to a spatial index (which happens on save for @Indexed(type=SPATIAL) fields).

The spatial index provider takes care for creating the appropriate 2d r-tree index entries and linking that to your domain node.

I think it should be possible to do that manually, i.e. creating the node in cypher and returning it and then using the spatail index provider to add this node to a certain location.

I know that florian did some work using cypher querying the spatial index. Have a quick look at the mailing list archive to find t he relevant thread(s).

HTH

Cheers

Michael

--
 
 

Michael Janiak

unread,
Sep 21, 2012, 11:05:03 AM9/21/12
to ne...@googlegroups.com
Ok that's great, I'll try it this way and report back hopefully within a week.

chris

unread,
Sep 24, 2012, 8:43:39 AM9/24/12
to ne...@googlegroups.com
What about creating nodes with spring data and @Indexed fields and then deleting them via cypher?

Do we need to delete the index manually (and how)? Or is it generally a bad idea to use Spring Data + data updating cypher queries together?
Reply all
Reply to author
Forward
0 new messages