Re: Janusgraph not able to find suitable index for a index enabled property key


Harshit Sharma
 

Hi Boxuan,

Thanks for the quick response. Actually, I'm following a strict schema in my service. 
i.e we first register a schema and then use it for vertex/edge creation.

So I'm not creating schema and vertex/edge in the same transaction. Only property key and index creation are happening in one transaction that is also at starting of the service only. From next time is index already exists then my service adds new properties to it.

These new properties are created after the creation of the index in a separate transaction are visible in management API printIndexes and printSchema. Also, they are visible in elastic mapping.



On Mon, Jan 10, 2022 at 12:26 PM Boxuan Li <liboxuan@...> wrote:
Sorry I misread your email. I thought you were using TEXT mapping only.

You said you were able to create index, add vertices and edges, and query them utilizing index in the same transaction, but not in a new transaction. Can you give complete code examples that demonstrate how you do so in the same transaction AND in a new transaction, as Marc asked? Specifically, do include how you open and commit/rollback transactions.

In addition, I wonder if this always happens no matter how long you wait, or only happens in a short period of time. Schema propagation takes some time, and you may see a sync delay across JanusGraph instances. If you create the index on one JanusGraph instance, and immediately insert & query data in another JanusGraph instance, it might be the case that schema propagation is not done yet and your other JanusGraph instance is not aware of the recently created index.

Another thing you could check is the Elasticsearch. After creating the index, do you see the index on your ES cluster? After inserting vertices/edges, do you see documents created at ES side?

Best,
Boxuan

On Mon, Jan 10, 2022 at 1:41 PM Harshit Sharma <harshit.sharma1080@...> wrote:
Only For SET cardinality, I'm using TEXT mapping because looks like SET does not work with TEXTSTRING.

On Mon, Jan 10, 2022 at 11:07 AM Harshit Sharma via lists.lfaidata.foundation <harshit.sharma1080=gmail.com@...> wrote:
but is that the reason I'm not able to use property keys created in a new transaction?
Also, can we mix index property keys of cardinality SET?

On Mon, Jan 10, 2022 at 10:56 AM Boxuan Li <liboxuan@...> wrote:
Hi Harshit,

You should use STRING mapping if you want exact string match. TEXT mapping is for full text search. See 

Best,
Boxuan

On Mon, Jan 10, 2022 at 1:15 PM Harshit Sharma <harshit.sharma1080@...> wrote:
Hi Marc,

1. Creation of property keys and indices in the schema + commit
      graph = (Janusgraph) GraphDBConfigurator.getGraph()
      mgmt = graph.openManagement()
      
     For Vertex ->
           propertyKey = mgmt.makePropertyKey(propertyKeyName).dataType (String.class).cardinality(Cardinality.SET).make()
          if(existingIndex) 
                janusgraphIndex = mgmt.getGraphIndex(VERTEX_INDEX_NAME)
                mgmt.addIndex(janusgraphIndex, propertyKey)
          else
               indexBuilder = mgmt.buildIndex(VERTEX_INDEX_NAME,  Vertex.class)
               if(cardinality is SET)
                        indexBuilder.addKey(propertyKey, String.class.equals(propertyKey.dataType) ? Mapping.TEXT.asParameter() : Mapping.DEFAULT.asParameter())
               else
                        indexBuilder.addKey(propertyKey, String.class.equals(propertyKey.dataType) ? Mapping.TEXTSTRING.asParameter() : Mapping.DEFAULT.asParameter())
  
    For Edge ->
            propertyKey = mgmt.makePropertyKey(propertyKeyName).dataType (String.class).cardinality(Cardinality.SINGLE).make()
             propertyKey = mgmt.makePropertyKey(propertyKeyName).dataType (String.class).cardinality(Cardinality.SINGLE).make()
          if(existingIndex) 
                janusgraphIndex = mgmt.getGraphIndex(EDGE_INDEX_NAME)
                mgmt.addIndex(janusgraphIndex, propertyKey)
          else
               indexBuilder = mgmt.buildIndex(EDGE_INDEX_NAME,  Vertex.class)
               if(cardinality is SET)
                        indexBuilder.addKey(propertyKey, String.class.equals(propertyKey.dataType) ? Mapping.TEXT.asParameter() : Mapping.DEFAULT.asParameter())
               else
                        indexBuilder.addKey(propertyKey, String.class.equals(propertyKey.dataType) ? Mapping.TEXTSTRING.asParameter() : Mapping.DEFAULT.asParameter())
         
            mgmt.commit();
    


       3.   Query of a vertex based on a property value in another transaction
             Let say i created a property key "domain_vertex_key1_s" for vertex
             Query = g.V().has("domain_vertex_key1_s", "val1);
             
             Let say I created a property key "domain_edge_key1_s" for edge
            
             Query = g.V().has("domain_vertex_key1_s","val2");
          

On Mon, 10 Jan, 2022, 12:46 am , <hadoopmarc@...> wrote:
Hi Harshit,

Can you please describe the steps you have taken in more detail:
  • creation of property keys and indices in the schema + commit,
  • creation of a vertex with a property in one committed transaction,
  • query of a vertex based on a property value in another transaction.

Marc



--
Regards,

Harshit Sharma
+91-9901459920



--
Regards,

Harshit Sharma
+91-9901459920



--
Regards,

Harshit Sharma
+91-9901459920

Join janusgraph-users@lists.lfaidata.foundation to automatically receive all group messages.