0
votes

While try to query a node with auto index in cypher it returns irrelevant nodes, As shown below i queried for node having contno='GESU5697150' but it returns some other node too.

neo4j-sh (0)$ start n=node:node_auto_index(contno='GESU5697150')  return n;
==> +----------------------------------------------------+
==> | n                                                  |
==> +----------------------------------------------------+
==> | Node[546290]{contno:"UACU5047693",sizetype:"40HC"} |
==> | Node[700914]{contno:"GESU5697150",sizetype:"40HC"} |
==> +----------------------------------------------------+
==> 2 rows 

Is this cypher / Neo4j issue?!. Due this i am facing problem with fetching the record at java code

Ncontno = autoNodeIndex.get("contno", contno).getSingle();

it throws below error

Exception in thread "main" java.util.NoSuchElementException: More than one eleme
nt in org.neo4j.index.impl.lucene.LuceneIndex$1@211b3c6a. First element is 'Node
[546290]' and the second element is 'Node[700914]'
2
Can you perhaps share what you did to import your data?Michael Hunger
@Michael Hunger , used below code firstNode = null; firstNode = graphDb.createNode(); firstNode.setProperty("contno", contno); firstNode.setProperty("sizetype", sizetype); container.add(firstNode, "contno", contno); container.add(firstNode, "sizetype",sizetype);Jeevanantham

2 Answers

1
votes

Autoindexes in Neo4j do not care about reindexing existing content when autoindexing config changes. If autoindexes were switched off while changing the contno property you'll see the described behaviour.

To fix this, you can set a property with its pre-existing value, triggering a implicit update of the auto index:

start n=node:node_auto_index(contno='GESU5697150') set n.contno = n.contno

Rerunning the original query should return just one element.

Schema indexes in Neo4j 2.0 address this inconvenient behaviour, see my blog post on various index types in Neo4j.

0
votes

i got a temporary solution for the above problem by verifying the contno in the collection of resultset.

hits = container.get("contno", contno);
  for (Node n : hits) {
    if (n.getProperty("contno").toString().equalsIgnoreCase(contno)) {
           Ncontno = n;
    } 
  }

so Ncontno will hold the expected contno. But still looking for better/ permanent solution