1

I have a graph made of two collections, one is a collection of 60,000 services and 10 products, and another is a collection of 1 million edges connecting a product to a service. We want to find all the service vertices on our graph that are connected to all 10 products. Basically, we want to find the intersection of all ten products at a single service, and return all the services at which this occurs. Each of the ten products have a distinct product ID. Does anyone have any suggestions on how to write a somewhat efficient query that returns these intersections of products? Below are some screenshots of a small portion of each of the collections, in JSON format.

first screenshot

second screenshot

1 Answer 1

1

The following query use two collections products and edgeCol. It first collects all of the 10 products in prods, then it iterates over all services and for every service it search for all connecting vertices (products) and checks if all of them contains in prods.

LET prods = (
  FOR product IN products
    FILTER product.ProductType == 'Product'
    RETURN product
)

FOR service IN products
  FILTER service.ProductType == 'Service'
  FILTER prods ALL IN (
    FOR v, e, p IN 1 OUTBOUND service edgeCol
      RETURN v
  )
  RETURN service

With only 10 products and over 60,000 services you should think about splitting your collection products into two collection products and services where products only contains your 10 products. You can then drop the field ProductType. This allow more performant querying.

LET prods = (
  FOR product IN products
    RETURN product
)

FOR service IN services
  FILTER prods ALL IN (
    FOR v, e, p IN 1 OUTBOUND service edgeCol
      RETURN v
  )
  RETURN service
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.