CristiC
CristiC

Reputation: 192

Using index in DSE graph

I'm trying to get the list of persons in a datastax graph that have the same address with other persons and the number of persons is between 3 and 5. This is the query:

g.V().hasLabel('person').match(__.as('p').out('has_address').as('a').dedup().count().as('nr'),__.as('p').out('has_address').as('a')).select('nr').is(inside(3,5)).select('p','a','nr').range(0,20)

At first run I've noticed this error messages:

Could not find an index to answer query clause and graph.allow_scan is disabled: ((label = person))

I've enabled graph.allow_scan=true and now it's working

I'm wondering how can I create an index to be able to run this query without enabling allow_scan=true ?

Thanks

Upvotes: 1

Views: 302

Answers (2)

bechbd
bechbd

Reputation: 6341

You can create an index by adding it to the schema using a command like this:

schema.vertexLabel('person').index('address').materialized().by('has_address').add()

Full documentation on adding indexes is available here: https://docs.datastax.com/en/latest-dse/datastax_enterprise/graph/using/createIndexes.html

You should not enable graph.allow_scan=true as under the covers it is turning on ALLOW FILTERING on the CQL queries. This will cause a lot of cluster scans and will inevitably time out with any real amount of data in the system. You should never enable this in any sort of production environment.

Upvotes: 1

Nicolas Delaforge
Nicolas Delaforge

Reputation: 1664

I am not sure that indexing is the solution for your problem. The best way to do this would be to reify addresses as nodes and look for nodes with an indegree between 3 and 5.

You can use index on textual fields of your address nodes.

Upvotes: 0

Related Questions