import * as knowledgeGraphService from "@arcgis/core/rest/knowledgeGraphService.js";
const knowledgeGraphService = await $arcgis.import("@arcgis/core/rest/knowledgeGraphService.js");
@arcgis/core/rest/knowledgeGraphService
A knowledge graph service is associated with several resources. One resource is a knowledge graph, which contains entities and relationships. Another resource is the data model that defines the entity types and relationship types in the graph. A third resource is the service definition which outlines the capabilities of the service. A knowledge graph service allows users to query both the knowledge graph and the data model. Entities and relationships can be added, updated or deleted from the knowledge graph using executeApplyEdits(). To visualize knowledge graph data on map, see knowledge graph layer.
Known Limitations
KnowledgeGraphService capabilities in version 4.26 of the SDK for Javascript are only supported against ArcGIS Enterprise version 11.1 and later. KnowledgeGraphService capabilities in version 4.25 of the SDK for Javascript are supported on ArcGIS Enterprise version 11.0 and earlier.
- See also
-
- KnowledgeGraphLayer for details on visualizing knowledge graph data.
Get started with ArcGIS Knowledge Server for overview of ArcGIS Knowledge for ArcGIS Enterprise
Hosted Knowledge Graph Service for information on managing knowledge graph services via ArcGIS Enterprise and the REST API
Get started with ArcGIS Knowledge (ArcGIS Pro) for information on ArcGIS Knowledge in ArcGIS Pro
const knowledgeGraphModule = await $arcgis.import("@arcgis/core/rest/knowledgeGraphService.js");
let knowledgeGraph;
// define url to knowledge graph service
const url = "https://myHostName.domain.com/server/rest/services/Hosted/myServiceName/KnowledgeGraphServer";
// fetch knowledge graph
KnowledgeGraphModule.fetchKnowledgeGraph(url)
.then((kg) => {
// do something with result
knowledgeGraph = kg;
console.log(knowledgeGraph);
});
Method Overview
| Name | Return Type | Summary | Object |
|---|---|---|---|
Promise<GraphAddFieldIndexResult> | Adds a field index for a particular property on an entity type or relationship type in a graph. | knowledgeGraphService | |
Promise<GraphAddPropertyResult> | Add a GraphProperty for a particular entity type or relationship type. | knowledgeGraphService | |
Promise<GraphAddNamedTypesResult> | Create new entity types or relationship types in your knowledge graph. | knowledgeGraphService | |
Promise<GraphApplyEditsResult> | Add, delete, or update entities and relationships in a knowledge graph service's graph resource. | knowledgeGraphService | |
Promise<GraphDeleteFieldIndexResult> | Deletes the field index for a particular property on an entity type or relationship type in a graph. | knowledgeGraphService | |
Promise<GraphDeletePropertyResult> | Delete a GraphProperty for a particular entity type or relationship type. | knowledgeGraphService | |
Promise<GraphDeleteNamedTypeResult> | Delete an entity type or relationship type from the graph. | knowledgeGraphService | |
Promise<CIMFilteredFindPathsResultJSON> | Executes a request to the ServerFilteredFindPaths GP tool. | knowledgeGraphService | |
Promise<JobInfo> | Executes an asynchronous request to the ServerFilteredFindPaths GP tool. | knowledgeGraphService | |
Promise<GraphQueryResult> | Executes a query on knowledge graph service's graph resource using the Esri implementation of openCypher and returns the results. | knowledgeGraphService | |
Promise<GraphQueryStreamingResult> | Execute a streaming query on a knowledge graph service's graph resource. | knowledgeGraphService | |
Promise<GraphQueryResult> | Search the knowledge graph using a full-text index that is automatically built on the property values in the graph and returns the result. | knowledgeGraphService | |
Promise<GraphQueryStreamingResult> | Execute a streaming search on a knowledge graph service's graph resource. | knowledgeGraphService | |
Promise<GraphUpdatePropertyResult> | Update a GraphProperty for a particular entity type or relationship type in the graph. | knowledgeGraphService | |
Promise<GraphUpdateNamedTypesResult> | Update an entity type or relationship type. | knowledgeGraphService | |
Promise<GraphUpdateSearchIndexResult> | Update the search index used by the knowledge graph. | knowledgeGraphService | |
Returns all client data keys existing on the knowledge graph service associated with the given knowledge graph. | knowledgeGraphService | ||
Promise<CIMFilteredFindPathsResultJSON> | Retrieves the filtered find path results from a job started by executeFindPathsAsynchronous. | knowledgeGraphService | |
Retrieves the specified client data keys from the knowledge graph service associated with the given knowledge graph, if they exist. | knowledgeGraphService | ||
Promise<KnowledgeGraph> | Retrieves the knowledge graph service based on the URL provided. | knowledgeGraphService | |
Refreshes the data model of the knowledge graph. | knowledgeGraphService |
Method Details
-
executeAddGraphFieldIndex
MethodexecuteAddGraphFieldIndex(graph, namedType, fieldIndexes, options){Promise<GraphAddFieldIndexResult>}Since: ArcGIS Maps SDK for JavaScript 4.33knowledgeGraphService since 4.25, executeAddGraphFieldIndex added at 4.33. -
Adds a field index for a particular property on an entity type or relationship type in a graph.
Note
- The user must have sufficient privileges to edit the data model for the knowledge graph service for this operation to be successful.
Parametersgraph KnowledgeGraphThe knowledge graph to update.
namedType StringThe name of the entity type or relationship type with the property for which to add a field index.
fieldIndexes FieldIndex[]The field indexes to add.
options RequestOptionsAdditional options to be used for the data request.
ReturnsType Description Promise<GraphAddFieldIndexResult> When resolved, the result is an GraphAddFieldIndexResult.
-
executeAddGraphProperties
MethodexecuteAddGraphProperties(graph, namedType, namedTypeProperties, options){Promise<GraphAddPropertyResult>}Since: ArcGIS Maps SDK for JavaScript 4.33knowledgeGraphService since 4.25, executeAddGraphProperties added at 4.33. -
Add a GraphProperty for a particular entity type or relationship type.
Note
- The user must have sufficient privileges to edit the data model for the knowledge graph service for this operation to be successful.
Parametersgraph KnowledgeGraphThe knowledge graph to update.
namedType StringThe name of the entity type or relationship type to update with the property to be updated.
namedTypeProperties GraphProperty[]A list of graph properties to add to the entity type or relationship type.
options RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphAddPropertyResult> When resolved, the result is an GraphAddPropertyResult.
-
executeAddNamedTypes
MethodexecuteAddNamedTypes(graph, namedTypes, options){Promise<GraphAddNamedTypesResult>}Since: ArcGIS Maps SDK for JavaScript 4.33knowledgeGraphService since 4.25, executeAddNamedTypes added at 4.33. -
Create new entity types or relationship types in your knowledge graph.
Note
- The user must have sufficient privileges to edit the data model for the knowledge graph service for this operation to be successful.
Parametersgraph KnowledgeGraphThe knowledge graph. Retrieved using
fetchKnowledgeGraph().namedTypes ObjectThe new entity types or relationship types to add to the graph.
SpecificationnewEntityTypes EntityType[]The new entityTypes to add to the graph.
newRelationshipTypes RelationshipType[]The new relationship types to add to the graph.
options RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphAddNamedTypesResult> - When resolved, the result is a GraphAddNamedTypesResult.
Exampleconst knowledgeGraphModule = await $arcgis.import("@arcgis/core/rest/knowledgeGraphService.js"); // use fetchKnowledgeGraph() to retrieve the knowledge graph // define the new entity type const newEntityType = { type: "entity", name: "Person", properties: [ { name: "nameProp", alias: "Name", fieldType: "esriFieldTypeString", role: "esriGraphPropertyRegular", }, ], }; // define a new relationship type const newRelationshipType = { type: "relationship", name: "knows", properties: [ { name: "dateMet", fieldType: "esriFieldTypeTimestampOffset", role: "esriGraphPropertyRegular", }, ], endPoints: [ { originEntityType: "Person", destinationEntityType: "Person", }, ], }; // add the new types, update the data model and get the updated graph. knowledgeGraphModule.executeAddNamedTypes(graph, { newEntityTypes: [newEntityType], newRelationshipTypes: [newRelationshipType] }).then((response) => { graph = response.updatedKnowledgeGraph; })
-
executeApplyEdits
MethodexecuteApplyEdits(graph, edits, requestOptions){Promise<GraphApplyEditsResult>} -
Add, delete, or update entities and relationships in a knowledge graph service's graph resource. This operation does not allow adding or deleting properties for entity types or relationship types. However, users can update an entity or relationship to change its property values.
Note
- The user must have sufficient privileges to edit content and editing must be enabled for the knowledge graph service for this operation to be successful.
Parametersgraph KnowledgeGraphThe knowledge graph associated with the service. See also ArcGIS REST APIs - Hosted Knowledge Graph Service.
edits GraphApplyEditsSpecifies the entities and relationships and their properties to add, update or delete.
requestOptions RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphApplyEditsResult> When resolved, the result is a GraphApplyEditsResult. Examples// sample executeApplyEdits() to add a new entity to the `Supplier` entity type const newEntity = new Entity({ typeName: "Supplier", properties: { Name: "Supplier 5", EmployeeCount: 681 } }); KnowledgeGraphModule.executeApplyEdits( graph, { entityAdds: [newEntity] }) .then((editResult) => { console.log("Graph Add Result", editResult); }); });// Basic example results of adding one entity to the `Supplier` entity type { editResults:[{ adds:[ { id: "{A1W5F4A8S-41F1-49A4-8412-ANIWN9906E88}", error: false }], deletes:[], typeName: "Supplier", updates:[] }], hasError: false, error: undefined }//update existing records const updateEntity = new Entity({ typeName: "Supplier", // update the EmployeeCount from 681 to 685 properties: { Name: "Supplier 5", EmployeeCount: 685 }, id:"{A1W5F4A8S-41F1-49A4-8412-ANIWN9906E88}" //id of entity already in knowledge graph }); const updateRelationship = new Relationship({ typeName: "buys_part", properties: { quantity: 5000 }, // origin and destination entities must already exist in the graph originId: "{AN4E4G85-41F1-49A4-8412-CACCC9906E88}", destinationId: "{9D2D6AFD-41F1-49A4-8412-1DGR8E5D6S1G4}" }); KnowledgeGraphModule.executeApplyEdits( graph, { entityUpdates: [updateEntity], relationshipUpdates: [updateRelationship] }) .then((editResult) => { console.log("Graph Update Result", editResult); }); });//delete existing records KnowledgeGraphModule.executeApplyEdits( graph, { entityDeletes: [{ typeName: "Supplier", ids: ["{AMGIE541G-41F1-49A4-8412-CACCC9906E88}", "{HNWIGHE15-WH52-2GE6-1A5W-A1F8W4FS3A1S5}"] },{ typeName: "Part", ids: ["{FNIW4GF1-ANFW-49A4-ANW7-GNWIGHAF4S51FS}"] }], relationshipDeletes: [{ typeName: "Buys_part", ids: ["{MH4E54G8E-MF4W-1842-2S44-15AF5W8F4S2W8}"] }], //delete all relationships connected to the deleted entities. options:{ cascadeDelete: true } }) .then((editResult) => { console.log("Graph Delete Result", editResult); }); });
-
executeDeleteGraphFieldIndex
MethodexecuteDeleteGraphFieldIndex(graph, namedType, fieldIndexNames, options){Promise<GraphDeleteFieldIndexResult>}Since: ArcGIS Maps SDK for JavaScript 4.33knowledgeGraphService since 4.25, executeDeleteGraphFieldIndex added at 4.33. -
Deletes the field index for a particular property on an entity type or relationship type in a graph.
Note
- The user must have sufficient privileges to edit the data model for the knowledge graph service for this operation to be successful.
Parametersgraph KnowledgeGraphThe knowledge graph to update.
namedType StringThe name of the entity type or relationship type to update.
The names of the field index to delete.
options RequestOptionsAdditional options to be used for the data request.
ReturnsType Description Promise<GraphDeleteFieldIndexResult> When resolved, the result is an GraphDeleteFieldIndexResult.
-
executeDeleteGraphProperty
MethodexecuteDeleteGraphProperty(graph, namedType, propertyName, options){Promise<GraphDeletePropertyResult>}Since: ArcGIS Maps SDK for JavaScript 4.33knowledgeGraphService since 4.25, executeDeleteGraphProperty added at 4.33. -
Delete a GraphProperty for a particular entity type or relationship type. A GraphProperty can only be deleted if the entity type or relationship type has no entity or relationship records in it.
Note
- The user must have sufficient privileges to edit the data model for the knowledge graph service for this operation to be successful.
Parametersgraph KnowledgeGraphThe knowledge graph to update.
namedType StringThe name of the entity type or relationship type to update with the property to be updated.
propertyName StringThe name of the GraphProperty to delete.
options RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphDeletePropertyResult> When resolved, the result is an GraphDeletePropertyResult.
-
executeDeleteNamedType
MethodexecuteDeleteNamedType(graph, namedType, options){Promise<GraphDeleteNamedTypeResult>}Since: ArcGIS Maps SDK for JavaScript 4.33knowledgeGraphService since 4.25, executeDeleteNamedType added at 4.33. -
Delete an entity type or relationship type from the graph. There must be no records of the type in the graph. To delete entities or relationships of the specified type, see executeApplyEdits().
Note
- The user must have sufficient privileges to edit the data model for the knowledge graph service for this operation to be successful.
Parametersgraph KnowledgeGraphThe knowledge graph. Retrieved using
fetchKnowledgeGraph().namedType StringThe name of the entity type or relationship type to delete.
options RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphDeleteNamedTypeResult> - When resolved, the result is a GraphDeleteNamedTypeResult.
Exampleconst knowledgeGraphModule = await $arcgis.import("@arcgis/core/rest/knowledgeGraphService.js"); // use fetchKnowledgeGraph() to retrieve the knowledge graph // Delete the type, update the data model and get the updated graph. knowledgeGraphModule .executeDeleteNamedTypes(graph,"knows") .then((response) => { graph = response.updatedKnowledgeGraph; })
-
executeFindPaths
MethodexecuteFindPaths(toolSettings, requestOptions){Promise<CIMFilteredFindPathsResultJSON>}beta -
Executes a request to the ServerFilteredFindPaths GP tool. Allows you to identify paths that connect the specified entities or entity types and satisfy all specified conditions. A path is made of a sequence of relationships and the corresponding entities.
Known Limitations
Find Paths can only be used with a Publisher or Administrator role. See Enterprise User types, roles, and privileges.
ParameterstoolSettings FindPathsToolSettingsThe pathfinding configuration such as origin and destination, waypoints and other tool settings. See FindPathToolSettings for the full list of available settings.
requestOptions RequestOptionsoptionalAdditional options specified in the data request. See RequestOptions for available properties.
ReturnsType Description Promise<CIMFilteredFindPathsResultJSON> - Returns paths found based on the configuration and pathfinding statistics.
ExampleknowledgeGraphService.executeFindPaths({ inKnowledgeGraphUrl: "https://sampleserver7.arcgisonline.com/server/rest/services/Hosted/BumbleBees/KnowledgeGraphServer", config: { type: "CIMFilteredFindPathsConfiguration", name: "exampleFFPconfiguration", originEntities: [ { type: "CIMFilteredFindPathsEntity", iD: devPathStart, entityTypeName: "User" } ], destinationEntities: [ { type: "CIMFilteredFindPathsEntity", iD: devPathEnd, entityTypeName: "Species" } ], pathFilters: [ { type: "CIMFilteredFindPathsPathFilter", iD: null, itemTypeName: "Observation", itemType: "Entity", filterType: "Include" } ], defaultTraversalDirectionType: "Any", entityUsage: "EachPair", pathMode: "All", minPathLength: 1, maxPathLength: 8, maxCountPaths: 100000 } });
-
executeFindPathsAsynchronous
MethodexecuteFindPathsAsynchronous(toolSettings, requestOptions){Promise<JobInfo>}beta -
Executes an asynchronous request to the ServerFilteredFindPaths GP tool. Allows you to identify paths that connect the specified entities or entity types and satisfy all specified conditions. A path is made of a sequence of relationships and the corresponding entities.
Known Limitations
Find Paths can only be used with a Publisher or Administrator role. See Enterprise User types, roles, and privileges.
ParameterstoolSettings FindPathsToolSettingsThe pathfinding configuration such as origin and destination, waypoints and other tool settings. See FindPathToolSettings for the full list of available settings.
requestOptions RequestOptionsoptionalThe options specified by the user in the data request. See RequestOptions for available properties.
Returns
-
executeQuery
MethodexecuteQuery(graph, queryArguments, requestOptions){Promise<GraphQueryResult>} -
Executes a query on knowledge graph service's graph resource using the Esri implementation of openCypher and returns the results.
Parametersgraph KnowledgeGraphThe knowledge graph associated with the service. See also ArcGIS REST APIs - Hosted Knowledge Graph Service.
queryArguments GraphQueryDefines the query to perform on the provided knowledge graph service.
requestOptions RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphQueryResult> When resolved, the result is an GraphQueryResult. Example// typical use case KnowledgeGraphModule.executeQuery( knowledgeGraph, //graph { // queryArguments openCypherQuery: "MATCH (n) RETURN n LIMIT 100", //query }).then((queryResult) => { // do something with the result });
-
executeQueryStreaming
MethodexecuteQueryStreaming(graph, queryArguments, requestOptions){Promise<GraphQueryStreamingResult>} -
Execute a streaming query on a knowledge graph service's graph resource. Streaming query returns a readable stream that must be read to access the returned graph data. Unlike executeQuery(), executeQueryStreaming() returns results in small chunks that can be processed immediately, without waiting for all results to be returned. Streaming query is faster and more efficient than executeQuery(). Streaming query also retrieves all matching records even if the total exceeds the
maxRecordCountdefined in the service without additional queries or pagination. Another benefit of streaming query is that the query is encoded which means that it is far smaller than a traditional HTTP GET or JSON POST body. This is especially important when trying to do a query on a very large argument, such as a large set of Ids or intersecting a complex geometry.The entities and relationships in the graph are queried by sending an Esri implementation of openCypher query.
Parametersgraph KnowledgeGraphThe knowledge graph associated with the service. See also ArcGIS REST APIs - Hosted Knowledge Graph Service.
queryArguments GraphQueryStreamingDefines the query to perform on the provided knowledge graph service. Optionally specify additional query parameters
requestOptions RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphQueryStreamingResult> When resolved, the result is an GraphQueryStreamingResult. Examples// sample streaming query using bind parameters // to search for entities with a the `name` property that matches a specific string // or have their geometry within a bounding box. // get all parts bought by each supplier. // query returns both the supplier and the part it buys. const query = `MATCH (s:Supplier)-[:buys_part]-(p:Part) WHERE s.name=$name OR esri.graph.ST_Intersects($geom, s.geometry) RETURN s,p`; KnowledgeGraphModule.executeQueryStreaming( knowledgeGraph, { openCypherQuery: query, bindParameters: { name: "Supplier 5", //bounding box around the area of Washington DC, USA geom: new Polygon({ rings: [ [ [38,-78], [39, -78], [39, -76], [-38, -76], [-38, -78], ], ], }), } }).then((streamingQueryResult)=>{ // streaming query returns a readableStream which must be read to access the returned graph data readStream(streamingQueryResult) });// a function to read the readable stream returned from the above query const readStream = async (streamingQueryResult) => { let time = Date.now(); let reader = streamingQueryResult.resultRowsStream.getReader(); try { while (true) { const { done, value } = await reader.read(); if (done) { console.log(`Completed database requests: ${(Date.now() - time) / 1000} seconds`); break; } console.log(`Chunk returned in: ${(Date.now() - time) / 1000} seconds`); // use the results // list the parts bought by each supplier let supplierParts = {}; // each element of the result array will contain one supplier and one part it buys for (var v in value){ let supplier = value[v][0].properties.Name let part = value [v][1].properties.Name if(!(supplier in supplierParts)){ supplierParts[supplier] = []; } // collect parts by supplier that buys them supplierParts[supplier].push(part); console.log(supplierParts); // result printed to the console: {Supplier 1:[Part1], Supplier 3:[Part2, Part3]} } } catch (err) { if (err.name === "AbortError") { console.log("Request aborted as expected"); } else { throw err; } } };// result stream from above query after it has been read "Streaming chunk returned in: 0.082 seconds" [ [{ "declaredClass": "esri.rest.knowledgeGraph.Entity", "properties": { "Name": "Supplier 1", "City": "Washington DC", "EmployeeCount": 31 }, "typeName": "Supplier", "id": "{57FDF2F3-34C8-48EF-9A3B-76ED9314C4D2}" },{ "declaredClass": "esri.rest.knowledgeGraph.Entity", "properties": { "Part_ID": 695401, "Name": "Part1", "Minimum_quantity": 360 }, "typeName": "Part", "id": "{IWN51W4-1AW8-A2W6-1AW5F-1AW8F9F4W51AS}", }], [{ "declaredClass": "esri.rest.knowledgeGraph.Entity", "properties": { "Name": "Supplier 2", "City": "Baltimore", "EmployeeCount": 53 }, "typeName": "Supplier", "id": "{1A4W8F5W-1WA8-5W6A-A1W8-A1W5F8W3S482A}" },{ "declaredClass": "esri.rest.knowledgeGraph.Entity", "properties": { "Part_ID": 695401, "Name": "Part2", "Minimum_quantity": 2500 }, "typeName": "Part", "id": "{A1W5F8W4F-A1W8-1894-16A5-A86WF4A8SFWD}", }], [{ "declaredClass": "esri.rest.knowledgeGraph.Entity", "properties": { "Name": "Supplier 2", "City": "Baltimore", "EmployeeCount": 53 }, "typeName": "Supplier", "id": "{1A4W8F5W-1WA8-5W6A-A1W8-L5H4G8RT1PK3}" },{ "declaredClass": "esri.rest.knowledgeGraph.Entity", "properties": { "Part_ID": 695401, "Name": "Part3", "Minimum_quantity": 5000 }, "typeName": "Part", "id": "{PTJ51FT-KY4H-1GY5-G1Y8-G1Y5K49G8Y4GHJ}", }] ]// aborting the query // create instance of native browser abort controller const controller = new AbortController(); // create query KnowledgeGraphModule.executeQueryStreaming( knowledgeGraph, { openCypherQuery: "MATCH (n) RETURN n LIMIT 100", }, { signal: controller.signal, } ) .then((streamingQueryResult) => { readStream(streamingQueryResult); }) // indicate that the stream was aborted .catch((err) => { if (err.name === "AbortError") { console.log("Request aborted as expected"); } // abort the query after half a second setTimeout(() => { console.log("Sending abort signal"); controller.abort(); }, 500);
-
executeSearch
MethodexecuteSearch(graph, searchArguments, requestOptions){Promise<GraphQueryResult>} -
Search the knowledge graph using a full-text index that is automatically built on the property values in the graph and returns the result. Search accepts Lucene search syntax. Use the DataModel to see the indexed fields for each RelationshipType and EntityType.
Parametersgraph KnowledgeGraphThe knowledge graph associated with the service. See also ArcGIS REST APIs - Hosted Knowledge Graph Service.
searchArguments GraphSearchDefines the free text search to run against a knowledge graph.
requestOptions RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphQueryResult> When resolved, the result is a GraphQueryResult that contains all records matching the search. If there are no matches the result will be empty. Examples// typical use case KnowledgeGraphModule.executeSearch( knowledgeGraph, //graph { // searchArguments searchQuery: "Sun", //search term typeCategoryFilter: "both" //search entities, relationships or both. }).then((searchResult) => { // do something with the result console.log(searchResult) });// sample search result { "declaredClass": "esri.rest.knowledgeGraph.GraphQueryResult", "resultRows": [ [ { "declaredClass": "esri.rest.knowledgeGraph.Entity", "properties": { "shape": { "declaredClass": "esri.geometry.Point", "cache": {}, "hasM": false, "hasZ": false, "latitude": 53.589000000000006, "longitude": -0.9633, "type": "point", "extent": null, "spatialReference": { "wkid": 4326 }, "x": -0.9633, "y": 53.589000000000006 }, "Name": "Suncommon", "Employee_Count": 400 }, "typeName": "Company", "id": "{WIPJ483T-U8UI-LLK9-YUI8-Y5YK8YGD88E9}", } ], [ { "declaredClass": "esri.rest.Relationship.Relationship", "originID": "{44027400-4B48-4FF2-B526-E27FC17EC246}", "destinationID": "{CB0CF580-3899-491E-8F10-0AD1DA4EE49B}", "properties": { "orderDay": "Sunday", "quantity": 15000 }, "typeName": "buys_part", "id": "{ABCDEFG-0000-1111-2222-0AD1DA4EE49B}" } ] }
-
executeSearchStreaming
MethodexecuteSearchStreaming(graph, searchArguments, requestOptions){Promise<GraphQueryStreamingResult>} -
Execute a streaming search on a knowledge graph service's graph resource. Streaming search returns a readable stream that must be read to access the returned data. Unlike executeSearch(), executeSearchStreaming() returns results in small chunks that can be processed immediately, without having to wait for all results to be returned. Streaming search is faster and more efficient than executeSearch(). Streaming search also retrieves all matching records even if the total exceeds the
searchMaxRecordCountdefined in the service without additional queries or pagination. Another benefit of streaming search is that the request is encoded which means that it is far smaller than a traditional HTTP GET or JSON POST body. This is especially important when trying to do a search on a very large argument, such as a large set of Ids.Streaming search accepts Lucene search syntax. Streaming search uses a full-text index that is automatically built on the property values in the graph. Use the DataModel to see the indexed fields for each RelationshipType and EntityType.
Parametersgraph KnowledgeGraphThe knowledge graph associated with the service. See also ArcGIS REST APIs - Hosted Knowledge Graph Service.
searchArguments GraphSearchStreamingDefine the free text search to execute against the knowledge graph. Optionally specify additional search parameters.
requestOptions RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphQueryStreamingResult> When resolved, the result is a GraphQueryStreamingResult that contains all records matching the search. If there are no matches the result will be empty. Examples// example search for "solar"with additional parameters KnowledgeGraphModule.executeSearchStreaming( knowledgeGraph, { searchQuery: "solar", typeCategoryFilter: "both", returnSearchContext: false, start: 1, num: 200, //return 200 records. namedTypesFilter: ["Company", "Supplier", "Part"], idsFilter: ["{G4E8G2S8D-2GS5-98S4-3S5D-S1DE7G45DS48}", "{FNWI1G5W-1A5W-3A5W-8412-A1W5F4W8F7AS}", "{9D2D6AFD-41F1-49A4-8412-CACCC9906E88}"] } ).then((streamingSearchResult)=>{ // the result of a streaming search is a readableStream which requires decoding. readStream(streamingSearchResult) })// a function to read the readable stream returned from the above query const readStream = async (streamingQueryResult) => { let time = Date.now(); let reader = streamingQueryResult.resultRowsStream.getReader(); try { while (true) { const { done, value } = await reader.read(); if (done) { console.log(`Completed database requests: ${(Date.now() - time) / 1000} seconds`, value); break; } console.log(`Chunk returned in: ${(Date.now() - time) / 1000} seconds`, value) } } catch (err) { if (err.name === "AbortError") { console.log("Request aborted as expected"); } else { throw err; } } };// sample result of streaming search result chunk read and printed to the console "Streaming chunk returned in: 0.082 seconds" [ [{ "declaredClass": "esri.rest.knowledgeGraph.Entity", "properties": { "Name": "Suncommon", "Employee_Count": 400, "energyType": "solar" }, "typeName": "Company", "id": "{G4E8G2S8D-2GS5-98S4-3S5D-S1DE7G45DS48}" }], [{ "declaredClass": "esri.rest.knowledgeGraph.Entity", "properties": { "Name": "Quality Solar Supply", "Supplier_code": "158B", "City": "New Orleans", }, "typeName": "Supplier", "id": "{FNWI1G5W-1A5W-3A5W-8412-A1W5F4W8F7AS}" }], [{ "declaredClass": "esri.rest.knowledgeGraph.Entity", "properties": { "Name": "Solar panel", "panel_type": "Polycrystalline", "price_per_unit": 400 }, "typeName": "Part", "id": "{9D2D6AFD-41F1-49A4-8412-CACCC9906E88}" }] ]
-
executeUpdateGraphProperty
MethodexecuteUpdateGraphProperty(graph, namedType, originalPropertyName, updatedProperties, options){Promise<GraphUpdatePropertyResult>}Since: ArcGIS Maps SDK for JavaScript 4.33knowledgeGraphService since 4.25, executeUpdateGraphProperty added at 4.33. -
Update a GraphProperty for a particular entity type or relationship type in the graph.
Note
- The user must have sufficient privileges to edit the data model for the knowledge graph service for this operation to be successful.
Parametersgraph KnowledgeGraphThe knowledge graph to update.
namedType StringThe name of the entity type or relationship type to update with the property to be updated.
originalPropertyName StringThe original name of the property to update.
updatedProperties UpdateGraphPropertiesThe updated properties for the entity type or relationship type property specified.
options RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphUpdatePropertyResult> When resolved, the result is an GraphUpdatePropertyResult.
-
executeUpdateNamedType
MethodexecuteUpdateNamedType(graph, namedType, updatedNamedType, options){Promise<GraphUpdateNamedTypesResult>}Since: ArcGIS Maps SDK for JavaScript 4.33knowledgeGraphService since 4.25, executeUpdateNamedType added at 4.33. -
Update an entity type or relationship type.
Note
- The user must have sufficient privileges to edit the data model for the knowledge graph service for this operation to be successful.
Parametersgraph KnowledgeGraphThe knowledge graph to update.
namedType StringThe name of the entity type or relationship type to update with the property to be updated.
updatedNamedType UpdateNamedTypeThe updated entity type or relationship type.
options RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphUpdateNamedTypesResult> - When resolved, the result is an GraphUpdateNamedTypesResult.
-
executeUpdateSearchIndex
MethodexecuteUpdateSearchIndex(graph, namedType, searchProperties, options){Promise<GraphUpdateSearchIndexResult>}Since: ArcGIS Maps SDK for JavaScript 4.33knowledgeGraphService since 4.25, executeUpdateSearchIndex added at 4.33. -
Update the search index used by the knowledge graph. Properties added to the search index are used identify matches to the search term provided in
executeSearchandexecuteSearchStreaming.Note
- The user must have sufficient privileges to edit the data model for the knowledge graph service for this operation to be successful.
Parametersgraph KnowledgeGraphThe knowledge graph to update.
namedType StringThe name of the entity or relationship type to update.
searchProperties ObjectThe properties of the named type with which to update the search index.
SpecificationaddSearchProperties SearchPropertiesThe properties of the specified entity type or relationship type to add to the search index.
removeSearchProperties SearchPropertiesThe properties of the specified entity type or relationship type to remove from the search index.
options RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<GraphUpdateSearchIndexResult> When resolved, the result is an GraphUpdateSearchIndexResult.
-
Returns all client data keys existing on the knowledge graph service associated with the given knowledge graph.
Parametersgraph KnowledgeGraphThe knowledge graph associated with the service. See also ArcGIS REST APIs - Hosted Knowledge Graph Service.
requestOptions RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsExample// typical use case const url = "https://myHostName.domain.com/server/rest/services/Hosted/myServiceName/KnowledgeGraphServer"; const knowledgeGraph = await knowledgeGraphService.fetchKnowledgeGraph(url) KnowledgeGraphModule.fetchAllClientDataKeys(knowledgeGraph) .then((clientDataKeys) => { // do something with result });
-
fetchAsynchronousFindPathsResultData
MethodfetchAsynchronousFindPathsResultData(jobInfo, requestOptions){Promise<CIMFilteredFindPathsResultJSON>} -
Retrieves the filtered find path results from a job started by executeFindPathsAsynchronous.
ParametersjobInfo JobInfoThe job info returned from executeFindPathsAsynchronous.
requestOptions RequestOptionsoptionalAdditional options specified in the data request.
ReturnsType Description Promise<CIMFilteredFindPathsResultJSON> - Returns all of the records in the paths found based on the configuration and statistics on how the paths were generated.
-
Retrieves the specified client data keys from the knowledge graph service associated with the given knowledge graph, if they exist. If a given client data key does not exist on the service, it is not returned in the result map.
ParametersSpecificationgraph KnowledgeGraphThe knowledge graph associated with the service. See also ArcGIS REST APIs - Hosted Knowledge Graph Service.
An array of client data keys to fetch from the service
options ObjectoptionalAdditional options when requesting client keys.
SpecificationignoreCache BooleanoptionalBy default, client data requests are cached by their version. When a previously requested key is requested again and the client data version for that key on the service is unchanged, the existing cached value is returned. When ignoreCache is
true, the request ignores the cache and fetches and returns the value from the service.requestOptions RequestOptionsoptionalAdditional options to be used for the data request.
ReturnsExample// typical use case const url = "https://myHostName.domain.com/server/rest/services/Hosted/myServiceName/KnowledgeGraphServer"; const knowledgeGraph = await knowledgeGraphService.fetchKnowledgeGraph(url) KnowledgeGraphModule.fetchClientDataAtKeys(knowledgeGraph, ["Person/LinkChart/LinkChartSubLayer"]) .then((clientDataResultMap) => { // do something with result });
-
fetchKnowledgeGraph
MethodfetchKnowledgeGraph(url){Promise<KnowledgeGraph>} -
Retrieves the knowledge graph service based on the URL provided.
Parameterurl StringURL to the ArcGIS Knowledge Server REST resource that represents a knowledge graph service.
ReturnsType Description Promise<KnowledgeGraph> When resolved, the result is a KnowledgeGraph. Example// typical use case const url = "https://myHostName.domain.com/server/rest/services/Hosted/myServiceName/KnowledgeGraphServer"; KnowledgeGraphModule.fetchKnowledgeGraph(url) .then((kg) => { // do something with result });
-
Refreshes the data model of the knowledge graph.
Parametergraph KnowledgeGraphThe knowledge graph associated with the service. See also ArcGIS REST APIs - Hosted Knowledge Graph Service.
Example// typical use case KnowledgeGraphModule.refreshDataModel(urlToKnowledgeGraph).then((newKG) => { // do something with result });
Type Definitions
-
CIMFilteredFindPathsError
Type DefinitionCIMFilteredFindPathsError Object -
Errors returned in the result of executeFindPaths and executeFindPathsAsynchronous. When no path has been found, and
CIMFilteredFindPathsResultJSON.configurationWarningis different fromNone, it is likely that the user made an unintended mistake in the configuration- Properties
-
type String
"CIMFilteredFindPathsError"
The value is always "CIMFilteredFindPathsError".
error StringErrors indicating why the tool could not be executed.
Possible Values:"None"|"ConfigurationHasTooManyInputEntities"|"ConfigurationIsTooComplex"|"PunctualEventHasNoTime"|"DurativeEventHasNoTime"|"DurativeEventHasOneMissingTime"|"DurativeEventHasSwappedTimes"
detailedErrorMessage StringDetails about the error.
-
CIMFilteredFindPathsResultJSON
Type DefinitionCIMFilteredFindPathsResultJSON Object -
The returned result of executeFindPaths and executeFindPathsAsynchronous.
- Properties
-
type String
The returned type of
executeFindPathsandexecuteFindPathsAsynchronous.The value is always "CIMFilteredFindPathsResult".
optional Any errors encountered while executing filtered find path.
configurationWarning StringWarnings indicating why a path was not found.
Possible Values:"None"|"AllOriginsAreExcluded"|"AllDestinationsAreExcluded"|"AllOptionalWaypointsAreExcluded"|"AtLeastOneMandatoryEntityWaypointIsExcluded"|"AtLeastOneMandatoryRelationshipWaypointIsExcluded"|"ReachedMaxPathLength"
statistics CIMFilteredFindPathsStatisticsPathfinding statistics.
The paths returned.
-
CIMFilteredFindPathsResultPaths
Type DefinitionCIMFilteredFindPathsResultPaths Object -
Represents the paths found by an executeFindPaths and executeFindPathsAsynchronous search.
We use a memory-optimized representation to avoid storing redundant information because it is often the case that a path shares some entities and relationships with many other paths, especially if the Filtered Find Paths configuration uses 'pathMode: "All"'.
Definition: a relationship group contains Knowledge Graph relationships associated to a single edge in the local graph.
Paths are encoded this way:
The path 'p' uses relationships groups
pathsBuffer[pathsEndIndex[p-1] .. pathsEndIndex[p]], and:- the origin of the first relationship group is the origin of the path
- the destination of the last relationship group is the destination of the path
A path of length zero (with entity 'e') has a single relationship group containing no relationship and where the origin and the destination are 'e'.
The relationships group 'g' has origin
entitiesUIDs[relationshipsGroupsFrom[g]]and destinationentitiesUIDs[RelationshipsGroupsTo[g]]. Its relationships arerelationshipsGroupsUIDsBuffer[relationshipsGroupsUIDsEndIndex[g-1] .. relationshipsGroupsUIDsEndIndex[g]].If relationshipsFrom[i] >= 0, relationship
relationshipsGroupsUIDsBuffer[i]has originentitiesUIDs[relationshipsFrom[i]]otherwise the relationship has been deleted after pathfinding.If relationshipsTo[i] >= 0, relationship
relationshipsGroupsUIDsBuffer[i]has destinationentitiesUIDs[relationshipsTo[i]]otherwise the relationship has been deleted after pathfinding.Note that origin and destination of a relationship may not match origin and destination of the relationship group because the relationship can be traversed backwards.
- Properties
-
type String
"CIMKGPaths"
The value is always "CIMKGPaths".
optional The list of entities that may be used in paths (not all entities are guaranteed to be used).
optional A list parallel to EntitiesUIDs representing entity type indices. If EntityTypes[i] >= 0, EntitiesUIDs[i] has type IndexedEntityTypes[EntityTypes[i]], otherwise the entity has been deleted after the find path operation.
optional The list of entity types, indexed by
entityTypesoptional The list of relationships that may be used in paths (not all relationships are guaranteed to be used). The list may contain duplicate elements.
optional A list parallel to
RelationshipsGroupsUIDsBufferrepresenting relationship type indices. If RelationshipTypes[i] >= 0, RelationshipsGroupsUIDsBuffer[i] has type IndexedRelationshipTypes[RelationshipTypes[i]], otherwise the relationship has been deleted after the find path operation.optional The list of relationship types, indexed by
relationshipTypesoptional The list of relationship group's relationship end indices (indexes into
relationshipsGroupsUIDsBuffer). Values must be positive.optional The list of relationship group's origin entity index (indexes into
entitiesUIDs). Values must be positive.optional The list of relationship group's destination entity index (indexes into
entitiesUIDs). Values must be positive.optional The list of relationship's origin entity index (indexes into
entitiesUIDs).optional The list of relationships destination entity index (indexes into
entitiesUIDs).optional List of relationships groups indices used by paths. Values must be positive.
optional List of paths relationships groups end indices (indexes into 'PathsBuffer'). Values must be positive.
-
CIMFilteredFindPathsStatistics
Type DefinitionCIMFilteredFindPathsStatistics Object -
Represents the statistics related to an executeFindPaths or executeFindPathsAsynchronous search. It contains the size of the local graph, and the number of openCypher "expansion" queries that have been issued to construct the local graph.
The local graph is an in-memory graph used for pathfinding where a node represents an entity in the Knowledge Graph and an edge represents one or many parallel relationships in the Knowledge Graph.
The local graph typically contains (much) less nodes than the Knowledge Graph, but enough nodes and edges to ensure that the pathfinding results are accurate. For example, to guarantee that all paths of length up to 'L' between 'A' and 'B' are present in the local graph, we ensure that the sum of counts of "expansion" queries related to 'A' and 'B' is greater or equal to 'L'.
- Properties
-
type String
"CIMFilteredFindPathsStatistics"
The value is always "CIMFilteredFindPathsStatistics".
optionalcountLocalGraphNodes NumberNumber of nodes found in the local graph.
optionalcountLocalGraphEdges NumberNumber of edges in the local graph. One edge in the local graph may represent multiple relationships when these relationships are parallel and equivalent with regard to pathfinding
optionalcountOriginExpansionQueries NumberGets or sets the count of expansion queries that were done to discover the neighborhood of some origin entities.
optionalcountDestinationExpansionQueries NumberGets or sets the count of expansion queries that were done to discover the neighborhood of some destination entities.
optionalcountWaypointsExpansionQueries NumberGets or sets the count of expansion queries that were done to discover the neighborhood of entity or relationship waypoints.
-
UpdateGraphProperties
Type DefinitionUpdateGraphProperties Object -
The properties of a GraphProperty that can be updated with
executeUpdateGraphProperty- Properties
-
optionalalias String
The display name of the graph property.
optionaleditable BooleanIf users are allowed to edit the property.
optionalrequired BooleanIf the property is required when a new record of that entity type or relationship type is created.
optionaldefaultVisibility BooleanIf the property is visible by default.
optionaldefaultValue unknownThe default value of the property.