0

I am using Titan 1.0 with elasticsearch as backend. From the titan documentation, I learned that for using elasticsearch, we use mixedIndex while building indexes. Here is my use case and problem: I am creating a graph database for registration data of a book store, for the data I have registration time, and other personal infos such as name and age. I want to query all the users that registered during given time range, in another words, I want a numeric comparison function for the query. This is how I create the index:

PropertyKey propertyKey = mgmt.makePropertyKey("registTime").dataType(Date.class)
    .cardinality(Cardinality.SINGLE).make()

timeIndex = mgmt.buildIndex("registeredTime",Vertex.class)
    .addKey("registTime", Mapping.TEXTSTRING.asParameter())
    .buildMixedIndex("search");

The timeIndex is created successfully, however, when I want to query the registered time with:

g.V().has("registTime", gt("2015-01-01 00:00:00.000+0000"))

it gives me:

WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - Query requires iterating over all vertices [()]. For better performance, use indexes

and it gives me an empty result, though I checked with gremlin command and confirmed the data is right there. Am I doing anything wrong? How can I solve this problem?

Mohamed Taher Alrefaie
  • 15,698
  • 9
  • 48
  • 66
RWM
  • 1
  • 3

1 Answers1

1

This error means that index has not been ENABLED yet.

Titan indexes have INSTALLED, REGISTERED, ENABLED and DISABLED states. For more information, have a look here.

You need to set the index state to ENABLED before you use it. Otherwise, you'll get this warning.

This is how you enable the index.

mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("registeredTime"), SchemaAction.ENABLE).get()
mgmt.commit()

Then wait for it until it switches,

ManagementSystem.awaitGraphIndexStatus(graph, propertyKeyIndexName)
                    .status(SchemaStatus.ENABLED)
                    .timeout(10, ChronoUnit.MINUTES) // set timeout to 10 min
                    .call();

So from now on, all added data will be indexed. If you want to index already added data:

mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("registeredTime"), SchemaAction.REINDEX).get()
mgmt.commit()

For more, read the docs here and here

Mohamed Taher Alrefaie
  • 15,698
  • 9
  • 48
  • 66
  • Thanks for your rapid reply. I found that my index is not created correctly, I wonder if it is because of the data type(Date.class). But I learned from the titan document that mixed index also support Date type. If I change it to String.class it would be created correctly. – RWM Jun 02 '16 at 00:38
  • And also, even it is correctly created, I got a NullPointerException at the line mgmt.updateIndex(mgmt.getGraphIndex("registeredTime"), SchemaAction.ENABLE_INDEX).get(); . – RWM Jun 02 '16 at 00:42