PattimusPrime
PattimusPrime

Reputation: 875

Integer index behavior in neo4j + lucene

I want to index an integer field on nodes in a large database (~20 million nodes). The behavior I would expect to work is as follows:

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

// Add node to graph (inserter is an instance of BatchInserter)
properties.put("id", 1000);
long node = inserter.createNode(properties);

// Add index 
index.add(node, properties);

// Retrieve node by index. RETURNS NULL!
IndexHits<Node> hits = index.query("id", 1000);

I add the key-value pair to the index and then query by it. Sadly, this doesn't work.

My current hackish workaround is to use a Lucene object and query by range:

// Add index 
properties.put("id", ValueContext.numeric(1000).indexNumeric());
index.add(node, properties);

// Retrieve node by index. This still returns null
IndexHits<Node> hits = index.query("id", 1000);

// However, this version works
hits = index.query(QueryContext.numericRange("id", 1000, 1000, true, true));

This is perfectly functional, but the range query is really dumb. Is there a way to run exact integer queries without this QueryContext.numericRange mess?

Upvotes: 0

Views: 604

Answers (1)

Ian
Ian

Reputation: 46

The index lookup you require is an exact match, not a query.

Try replacing index.query("id", 1000) with index.get("id", 1000)

Upvotes: 2

Related Questions