Query Knowledge Graph

When you index content into Knowledge Graph it stores the nodes and edges for your graph. You can then query Knowledge Graph to find information about your data.

Knowledge Graph has the following querying actions. For full details of the actions and action parameters, see Graph Query Actions.

  • GetNeighbors. Returns the neighbors of the nodes that you specify.

    For example, if your graph contains wikipedia articles, you can find a list of related concepts for a specified article. The following action finds a list of up to 10 articles that the Hewlett-Packard article links to.

    action=GetNeighbors&SourceNames=Hewlett&20Packard&20Enterprise&MaxResults=10
  • GetNeighborhood. Returns the nodes within a specified distance of the nodes that you specify. This action also returns the edges between all the nodes in the set (input and result nodes), to create a subgraph from a starting set of nodes and closely related nodes. GetNeighborhood allows you to find out what a particular part of the graph looks like, without knowing the names or IDs of all the nodes.

    For example, if your graph contains wikipedia articles, you can create a neighborhood subgraph of articles that are closely related to a specified article. The following action finds up to 15 articles that are closely related to the articles on Chemistry and Physics, and any connections between them.

    action=GetNeighborhood&SourceNames=Chemistry,Physics&MaxResults=15
  • GetCommonNeighbors. Returns neighbors of a list of nodes that you specify, together with a commonality value that indicates how many of your list of nodes the neighbor shares.

    For example, if your graph contains wikipedia articles, you can find a list of concepts that are related to two or more articles. The following action finds a list of up to 10 articles that the articles on Barack Obama and David Cameron both link to.

    action=GetCommonNeighbors&SourceNames=Barack%20Obama,David%20Cameron&MaxResults=10
  • GetShortestPath. Finds the shortest route between two specified nodes, using existing edges in the graph.

    For example, if your graph is made up of connections between places, you can find a route between them. The following action uses the graph to find the shortest route between London and Manchester. It uses the Weighted method, which returns the route with the lowest value for the sum of the weights of the edges. For this example, the weights might represent the physical distance or travel time between two nodes in the route.

    action=GetShortestPath&SourceName=London&TargetName=Manchester&Method=Weighted
  • GetShortestPaths. Finds all nodes within a specified distance of a specified node, using existing edges in the graph.

    For example, if your graph is made up of connections between places, you can find all places within a specified distance of your starting point. The following action uses the graph to find all places within a distance of 10 from Cambridge. It uses the Weighted method to calculate the distance. For this example, the weights might represent the physical distance or travel time between two nodes.

    action=GetShortestPaths&SourceName=Cambridge&Method=Weighted&MaxDistance=10
  • GetSubgraph. Returns a subgraph based on the set of nodes that you specify, showing all the edges that occur between these nodes.

    For example, if your graph contains a list of employees in your company and their contacts, you can create a subgraph that shows the connections in a particular department. The following action creates a subgraph for five users, where the users are specified by Knowledge Graph node ID.

    action=GetSubgraph&NodeIDs=10230,20345,20346,20347,21968
  • SuggestLinks. Returns a list of nodes that are connected to neighbors of a node that you specify and that are not also neighbors of the specified node.

    For example, if your graph contains a list of users and their contacts, you can find friends of friends that a particular user might want to connect to. The following action finds contacts who are friends of friends of a user with the e-mail address Alice@example.com.

    action=SuggestLinks&NodeName=Alice%40example.com

Find Graph Details

The following actions allow you to get more information about your graph. For full details of the actions and action parameters, see Graph Query Actions.

  • GetNodes. Lists the nodes in your graph. You can use this action to find the node IDs of your nodes.

    action=GetNodes&Sort=None
  • SummarizeGraph. Returns a summary of the number of nodes and edges in your graphs, and details of the attributes stored for your edges.

    action=SummarizeGraph