0
votes

I turned on node auto-indexing and it's indexing the properties I need. If I start up the Neo4j server and open the webadmin, I see that there is an index called node_auto_index as per this post. It works perfectly from the webadmin and I can run Cypher queries like this:

START n=node:node_auto_index('__type:user AND __username:admin') RETURN n

The query returns exactly what I expect. However, if I shut down the server and open the DB in embedded mode from a Scala application, this doesn't work. If I try to run the same Cypher query, I get an error that node_auto_index doesn't exist. I checked the GraphDatabaseService properties, and auto indexing is up and running on the right keys, but when getting a list of all of the index names, the list is always empty. And I can't use the AutoIndex API because it only indexes on one property, and I definitely need both.

So from this point, what would be the best way to ago about querying the auto-index with multiple properties from my Scala (Java) code?

EDIT: I noticed that the ReadableIndex interface (which is what the auto-index is) can take a query string. I can't find much documentation on it, so I'm going to try a few things, but is there any chance that could take a Cypher query? Or just the single-quoted string in my query above?

1
What code are you using to run the Cypher query from Scala?Eve Freeman
I'm using this exact code: docs.neo4j.org/chunked/milestone/tutorials-cypher-java.html. But I actually just figured out my issue. I'll answer my own question now.GJK

1 Answers

0
votes

Turns out that the query function of the ReadableIndex actually takes a Lucene Query, which I now realize is what I had quoted above. So calling this code:

val nodes = db.index.getNodeAutoIndexer.getAutoIndex.query("__type:user AND __username:admin")

Gave me exactly what I wanted.