Getting existing Indexs By Java

94 views
Skip to first unread message

Mahdi Negahi

unread,
Apr 27, 2012, 9:03:04 AM4/27/12
to ne...@googlegroups.com


I want to fetch all available Index in a graph database by Java. Then, I want to fetch all indexed node on them. we don't have any assumption about Index name, the program must be fetch them automatically.

now I can fetch all index name by this line :

for(String s :_graphDb.index().nodeIndexNames())
   {
   }

but i stuck in next step.

please advice me!

regard
Mahdi

Axel Morgner

unread,
Apr 27, 2012, 9:19:47 AM4/27/12
to ne...@googlegroups.com
try

for(String s :_graphDb.index().nodeIndexNames())
{
graphDb.index().forNodes(s).query(...)
}
...

Mahdi Negahi

unread,
Apr 27, 2012, 1:27:51 PM4/27/12
to ne...@googlegroups.com
I want to store all nodes that they indexed by corresponding index to other databases. imagine our database has 1 node that it indexed by a index which is called "PrimaryKey" the key of the index is "PKEY" and the value is "125". we just added this Index by following code:

IndexManager index = graphDb.index();
Index<Node> PrimaryKey= index.forNodes( "PrimaryKey" );
PrimaryKey.add( node1, "PKEY", "125" ); 


so when we pars the databases when we analyse this node , the application must be fetch all the node index (PrimaryKey) the key of the index (PKEY) and the value (125).
I want to save these information in other databases.

Thanks for ur answer 
Mahdi

Michael Hunger

unread,
Apr 27, 2012, 2:31:42 PM4/27/12
to ne...@googlegroups.com
Did you store the information also as property on the node?

Otherwise you'd have to use some low level lucene operations to extract it, you can do it manually with the lucene tool called luke,
It can export this data into xml, see:  http://www.getopt.org/luke/
"Export to XML - exports index data and metadata to XML file. This is available both from the GUI and from the command-line."

I don't have the code at hand to read and use the lucene database format programmatically.

Michael

Mahdi Negahi

unread,
Apr 28, 2012, 10:13:44 PM4/28/12
to ne...@googlegroups.com
thanks for ur reply

The application must be worked with all graph, so I don't know the information is stored as node's property.

Mattias Persson

unread,
Apr 29, 2012, 8:38:59 AM4/29/12
to ne...@googlegroups.com
The values are stored in the lucene documents, but API-wise you cannot reach them I'm afraid.

2012/4/29 Mahdi Negahi <negahi...@gmail.com>



--
Mattias Persson, [mat...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com

Mahdi Negahi

unread,
Apr 30, 2012, 12:22:32 AM4/30/12
to ne...@googlegroups.com
even we can not convert items that they indexed to the XML or something like that.

Peter Neubauer

unread,
Apr 30, 2012, 1:22:13 AM4/30/12
to ne...@googlegroups.com

Sorry Mahdi,
It's hard to read your question. Do you have any code that shows your problem?

Mahdi Negahi

unread,
May 3, 2012, 11:58:26 PM5/3/12
to ne...@googlegroups.com
Sorry Peter 

you know I want convert a Neo4j graph to other databases . I convert all the component of a Neo4j database to the target. But I missed index item in the target environment. I want to know, Is there any chance to convert indexed item to the XML or something else ?

for example, imagine we have a graph with two nodes and a relationship.

node 1 : 
ID: 1
Property --> Name: Mahdi
Index (PKEY)--> PrimeryKey: 50

node 2:
ID: 2
Property --> Name: Peter 
Index (PKEY)--> PrimeryKey: 1


relationship:

Type----> Know
property ---> Since: 2012


so we past this graph to the application and the result something like this

<Node ID=1> <Index Name="PKEY" Key="PrimeryKey" Value="50 /> </Node>
<Node ID=2> <Index Name="PKEY" Key="PrimeryKey" Value="1 /> </Node>


it is much noticeable that we do not have any assumption about index's name , index key .... we just past a graph to the program or function and it returns the : index name  , index key and index value with a specific format

Duane Nickull

unread,
May 4, 2012, 12:19:54 AM5/4/12
to ne...@googlegroups.com
Inline:
***********************************
Consulting and Contracting; Proven Results!
i.  Neo4J, Java, LiveCycle ES, Flex, AIR, CQ5 & Mobile
t.  @duanechaos



From: Mahdi Negahi <negahi...@gmail.com>
Reply-To: "ne...@googlegroups.com" <ne...@googlegroups.com>
Date: Thursday, 3 May, 2012 8:58 PM
To: "ne...@googlegroups.com" <ne...@googlegroups.com>
Subject: Re: [Neo4j] Getting existing Indexs By Java

Sorry Peter 

you know I want convert a Neo4j graph to other databases .

DN: So that is just silly.  Why would anyone want to ever do that?  ;-)

I convert all the component of a Neo4j database to the target. But I missed index item in the target environment. I want to know, Is there any chance to convert indexed item to the XML or something else ?

DN: Okay , seriously, there are 6 major classes in Java that work with indexes.
IndexHits
IndexImplementation
IndexIterable
IndexManager
IndexProvider


I think you why you want, the INdexManager has a lot of methods worth exploring.  Whoever designed this class clearly thought of your use case.  I will provide a caveat however.  I may have misunderstood your request.  If not, IndexManager has a method nodeIndexNames()
 Which returns an array 9String[]) of all the nodes that are indexes.  One returned, you can serialize them into any data format with simple parlous tricks.

Perhaps I did not understand your request?

Duane

Peter Neubauer

unread,
May 4, 2012, 1:01:58 AM5/4/12
to ne...@googlegroups.com

Mahdi,
If I understand you right, you are looking for a way to export a neo4J graphics into a format like XML that includes the indexed properties?

Mahdi Negahi

unread,
May 5, 2012, 12:11:31 AM5/5/12
to ne...@googlegroups.com
Dear Überity and Peter 

Thanks for ur reply.

 DN: So that is just silly.  Why would anyone want to ever do that?  ;-)

I work on data portability in cloud databases so my portability patterns consist of two migration patterns. as result, it not much silly as you thought  ;-)
___________________________________________________________________________________________

I only want to export indexed properties but in a specific way , I must to know the owner of those properties.

for example I loop in every nodes. I must to realized that node has some indexed properties. then extract them in XML or something else ( SQL Table).

for example the following code is in Neo4j Document 

IndexManager index = graphDb.index();
Index<Node> actors = index.forNodes( "actors" );
Node reeves = graphDb.createNode();
actors.add( reeves, "name", "Keanu Reeves" );

so I want to get the following output from the above code. Please notice the function must be work with any graph. that means we do not have any knowledge about index name ("actors"), properties key ("name").

<Node ID=1>
                <Indexs name="actors">
                             <Index key="name" value="Keanu Reeves" />
                </indexs>
</Node>

I hope I can say what exactly my problem.

Michael Hunger

unread,
May 5, 2012, 4:04:57 AM5/5/12
to ne...@googlegroups.com
Mahdi,

as mentioned it doesn't work out of the box. 

The only thing I can suggest to you right now is to use the Lucene classes IndexReader and Document
point them to each of the index/lucene/node/* and  index/lucene/relationship/* directories read all documents and all fields of each document and use this information.


shouldn't be that complicated, just a few lines of code.

Make sure that all transactions are completed when you do this, otherwise you might get stale data.

Michael
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages