how to create indexes?

268 views
Skip to first unread message

Li Li

unread,
May 30, 2012, 3:01:03 AM5/30/12
to ne...@googlegroups.com
hi all
I have inserted many nodes and want to add indexes by nodes'
certain properties.
I can use rest (batch) api to add nodes to an index. But it need I
traverse all the nodes and add them to an index. is there any
api that can do thing like sql "create index on name column". I mean
it automatically add all nodes which has a name property to
an index?
I read the document of auto indexing. and the neo4j.properties file
#Autoindexing

#enable auto-indexing for nodes, default is false
#node_autoindexing_enabled=true

# The node property keys to be auto-indexed, if enabled
#node_keys_indexable=name,age

I want to indexing age by keyword analyzer(exact matching) and
name by whitespace(or other my customized analyzer). How can I
do this? I am familiar with lucene. but where can I configure my analyzer?

Stefan Armbruster

unread,
May 30, 2012, 4:45:01 AM5/30/12
to ne...@googlegroups.com
Hi,

autoindexing is probably what you're looking for. Note that switching on
autoindexing does not pick up previously existing contents into the
index, it only tracks changes from the timepoint of the config change on.
To index prexisiting contents iterate over all nodes/relationships and
set the respective properties with their existing values:

GlobalGraphOperations ggo = GlobalGraphOperations.at(graphDb);
for (Node node: ggo.getAllNodes()) {
for (String key: graphDb.index().getNodeAutoIndexer()
.getAutoIndexedProperties() ) {
node.setProperty(key, node.getProperty(key));
}
}
for (Relationship rel: ggo.getAllRelationships()) {
for (String key: graphDb.index().getRelationshipAutoIndexer()
.getAutoIndexedProperties() ) {
rel.setProperty(key, rel.getProperty(key));
}
}

And yes, you can configure the underlying index. Be careful, this must
be done at the very first setup of the index. See
http://docs.neo4j.org/chunked/stable/indexing-create-advanced.html, note
that when configuring the autoindex, you have to use the magic names
"node_auto_index" and "relationship_auto_index".

Regards,
Stefan

Li Li

unread,
May 30, 2012, 5:10:47 AM5/30/12
to ne...@googlegroups.com
I have read http://docs.neo4j.org/chunked/snapshot/indexing-create-advanced.html
but I use the server mode instead of embedded mode.
how to configure neo4j.properties to support auto indexing with full
text matching?

Jim Webber

unread,
May 30, 2012, 2:50:20 PM5/30/12
to ne...@googlegroups.com
Hi there,

The docs are the same irrespective of whether you're *configuring* server or embedded (they're the same code under the covers).

But to *use* indexes through the server's REST API, see:

http://docs.neo4j.org/chunked/stable/rest-api-indexes.html
http://docs.neo4j.org/chunked/stable/rest-api-unique-indexes.html
http://docs.neo4j.org/chunked/stable/rest-api-auto-indexes.html

And in general for the REST API:

http://docs.neo4j.org/chunked/stable/rest-api.html

Jim
Reply all
Reply to author
Forward
0 new messages