Knowledge graph functions are only available when using a knowledge graph service. The following functions allow you to access and query knowledge graphs.
KnowledgeGraphByPortalItem
KnowledgeGraphByPortalItem(portalObject, itemId) -> KnowledgeGraph
Function bundle: Knowledge Graph
Profiles: Field Calculation | Popups
Returns a knowledge graph from a portal item.
Parameters
- portalObject: Portal - The Portal from which to query features.
- itemId: Text - The GUID of the portal item referencing a knowledge graph service. This value must be a text literal.
Return value: KnowledgeGraph
Additional resources
- Get started with ArcGIS Knowledge Server
- Get started with ArcGIS Knowledge (ArcGIS Pro)
- Introduction to knowledge graph service in the ArcGIS Maps SDK for JavaScript
Example
Returns the knowledge graph from the portal item.
var knowledgeGraph = KnowledgeGraphByPortalItem(
Portal('https://www.arcgis.com'),
'7b1fb95ab77f40bf8aa09c8b59045449',
);
QueryGraph
QueryGraph(graph, openCypherQuery, queryParameters?) -> Array
Function bundle: Knowledge Graph
Profiles: Popups | Field Calculation
Queries a knowledge graph with an openCypher query and returns the set of entities and relationships in a graph, along with their properties.
Parameters
- graph: KnowledgeGraph - The knowledge graph to query.
- openCypherQuery: Text - The openCypher query to be executed against the knowledge graph.
- queryParameters (Optional): Dictionary - A dictionary of named query parameters for the openCypher query. The parameter names or keys in the dictionary are case-sensitive. Parameters accepted depend on the external graph store and can be of type:
Array
,Date
,Dictionary
,Geometry
,Number
,Text
Return value: Array
Additional resources
- Get started with ArcGIS Knowledge Server
- Get started with ArcGIS Knowledge (ArcGIS Pro)
- Introduction to knowledge graph service in the ArcGIS Maps SDK for JavaScript
Examples
Queries the knowledge graph for information about the Student
entities it contains.
var results = QueryGraph(
knowledgeGraph,
'MATCH (p:Student)-[e:EnrolledAt]->(s:School)
WHERE s.name = "Eastside Elementary"
RETURN p,e,s.principal,s.numStaff
LIMIT 1');
return Text(results);
Queries the knowledge graph using bind parameters.
// searches for entities with a `name` property that matches the given string in the query parameters
// OR falls within the given geom bounding box
// query returns both the supplier and the part that it buys
var query = `MATCH (s:Supplier)-[:buys_part]-(p:Part)
WHERE s.name=$name OR esri.graph.ST_Intersects($geom, s.geometry)
RETURN s,p`;
var results = QueryGraph(
$graph,
query,
{
"name": "Supplier 1",
"geom": Polygon({
rings: [[
[38,-78],
[39,-79],
[39,-76],
[-38,-76],
[-38,-78]
]]
})
}
);