Pattern queries
The pattern queries allow users to create queries that help users to search data for that patterns. For example, user can search parties that are connected to a watchlisted party.
POST batch
This endpoint ingests data if the pattern is not present in the database. If the pattern already exists in the database, it will be updated with the new values.
Swagger documentation for the service can be accessed at: https://<host>/ibm/api/graphapi/explorer/#!/Graph_API_Service/patternBatchIngestion
.
Syntax
Header: x-access-token
Endpoint URL: https://<host>/graphapiservice/graphanalytics/explore/pattern/batch
The following code snippet is an example of a request JSON body:
{
"objects": [
{
"objectType": "pattern",
"properties": {
"queryName": "Account list",
"query": "match (a:account) return a limit 30",
"queryType": "cypher",
"context": "aml",
"createdBy": "graphadmin",
"description": "List of Accounts",
"productQuery": false,
"share": true,
"offline": false,
"repeat": "none",
"schedule": true,
"schedulePeriod": 0,
"scheduleDay": "Friday",
"alert": false
}
},
{
"objectType": "pattern",
"properties": {
"queryName": "Party network",
"query": "match p = (:party{node_id:'2049'})-[*..2]-() return p",
"queryType": "cypher",
"context": "aml",
"createdBy": "graphadmin",
"description": "Party 2 hop network",
"productQuery": true,
"share": true,
"offline": false,
"repeat": "none",
"schedule": true,
"schedulePeriod": 0,
"scheduleDay": "Friday",
"alert": false
}
}
]
}
The following code snippet is an example of a JSON response body for a successful request when the patterns are not in the database:
{
"data": {
"Patterns Added": 2,
"Patterns Updated": 0
},
"error": {}
}
The following code snippet is an example of a JSON response body for a successful request when the patterns are already in the database:
{
"data": {
"Patterns Added": 0,
"Patterns Updated": 2
},
"error": {}
}
The following code snippet is an example of a JSON response body for a failed request.
"data": {},
"error": {
"code": "invalid_value",
"message": "The <description> field in query Account list is not having valid value. List of special characters allowed in <description> are [ ] : / _ - * & # , . ( ) Please remove other special characters."
}
}
Mandatory fields
The POST endpoint requires the following mandatory fields to be present in the JSON object.
objectType
must be set topattern
queryName
must have a unique value to create a new pattern in the databasequery
queryType
must be set tocypher
. The value is not case sensitive.context
createdBy
productQuery
must be set to eithertrue
orfalse
Failure response body:
{ "data": {}, "error": { "code": "invalid_value", "message": "The <queryType> field in query Account list should be set to <cypher>" } }
Other fields mentioned in the JSON object are optional. If these key-values are not present, they are set to default values.
Example: Adding patterns to the database
The following code snippets show examples of a request, response, and output using the POST method to add patterns to the database.
Request:
{
"objects":
[
{
"objectType": "pattern",
"properties":
{
"queryName": "Account list",
"query": "match (a:account) return a limit 30",
"queryType": "cypher",
"context": "aml",
"createdBy": "graphadmin",
"productQuery": true
}
}
]
}
Response:
{
"data":
{
"Patterns Added": 1,
"Patterns Updated": 0
},
"error": {}
}
Output:
{
"service": "Get Matched QueryName",
"responseCode": 200,
"data":
[
{
"query": "match (a:account) return a limit 30",
"queryName": "Account list",
"queryType": "cypher",
"createdBy": "graphadmin",
"description": "",
"share": false,
"offline": false,
"repeat": "none",
"schedule": false,
"schedulePeriod": -1,
"scheduleDay": "",
"alert": false,
"productQuery": true,
"createDate": "Fri Sep 11 07:43:07 UTC 2020",
"updateDate": "Fri Sep 11 07:43:07 UTC 2020",
"id": 4280
}
],
"error": ""
}
Example: Updating patterns in the database
The following code snippets show examples of a request, response, and output using the POST method to update patterns to the database. This request adds values for alert, description, and share properties and updates the productQuery property.
Request:
{
"objects":
[
{
"objectType": "pattern",
"properties":
{
"queryName": "Account list",
"query": "match (a:account) return a limit 30",
"queryType": "cypher",
"context": "aml",
"createdBy": "graphadmin",
"productQuery": false,
"alert": true,
"description: "List of accounts",
"share": true
}
}
]
}
Response:
{
"data":
{
"Patterns Added": 0,
"Patterns Updated": 1
},
"error": {}
}
Output:
{
"service": "Get Matched QueryName",
"responseCode": 200,
"data":
[
{
"query": "match (a:account) return a limit 30",
"queryName": "Account list",
"queryType": "cypher",
"createdBy": "graphadmin",
"description": "List of accounts",
"share": true,
"offline": false,
"repeat": "none",
"schedule": false,
"schedulePeriod": -1,
"scheduleDay": "",
"alert": true,
"productQuery": false,
"createDate": "Fri Sep 11 07:43:07 UTC 2020",
"updateDate": "Fri Sep 11 12:47:55 UTC 2020",
"id": 4280
}
],
"error": ""
}