Skip to main content
Skip table of contents

Testing PII and ROT rules

This article explains how to test the query (“RawQuery”) from custom PII and ROT rule files.

Review the below two articles for more information on PII and ROT.

Review the following article for more information on custom PII and ROT.

Before applying new custom rules or editing existing rules in Control Center, you may want to test the query portion of the rule file for the following reasons:

  • Verify that the syntax of the “RawQuery” is correct

  • Verify that your query will return the expected number of results against your data source(s)

  • Edit the query until the results against your data source(s) are satisfactory

Examples of existing rules:

PII (potential_pii-Email_address.json)

{
"Name": "Email address",
"Description": "",
"FieldName": "potential_pii",
"FieldValue": "email_address",
"Sensitivity": 0,
"RegexPattern": "(\\b[A-Za-z0-9.!#$%^&'*+/=?^_`{|}~-]+@[A-Za-z0-9-]+(?:\\.[A-Za-z0-9-]+)\\b)",
"LuhnValidate": "false",
"RawQuery": {
"bool": {
"must": [
{
"exists": {
"field": "fullText"
}
}
],
"must_not": [],
"should": [
{
"match_phrase": {
"fullText": "e-mail"
}
},
{
"match_phrase": {
"fullText": "email"
}
},
{
"match_phrase": {
"fullText": "emailaddress"
}
},
{
"match_phrase": {
"fullText": "user"
}
},
{
"match_phrase": {
"fullText": "login"
}
},
{
"match_phrase": {
"fullText": "username"
}
},
{
"match_phrase": {
"fullText": "contact"
}
}
],
"minimum_should_match": 1,
"filter": []
}
}
}

ROT (rot_obsolete-log.json)

{
"Name":"Log",
"Description":"Old log files",
"FieldName":"rot_obsolete",
"FieldValue":"log",
"RawQuery": {
"bool": {
"must": [
{
"terms": {
"extension": [
"log",
"LOG"
]
}
}
],
"filter": {
"range": {
"lastWriteTimeUtc": {
"lte": "now-6M/d"
}
}
},
"must_not": [
{
"term": {
"rot_obsolete": "log"
}
}
]
}
}
}

Steps to test query:

In both examples above, we can test the query portion of rules to see what the results will be against your data source(s).

  1. Open the PII or ROT rule (json file) you want to test the query for

    • you can open this in a text editing applications like Notepad, Notepad++, Visual Studion, etc.

  2. Copy the text from the “RawQuery” portion of the file

    • starting from the first brace (curly bracket) after "RawQuery":, to the second last brace (curly bracket) of the text

    • example below

      image-20250925-161627.png
  3. Login to OpenSearch Dashboards. The Default URL is http://localhost:5601/

  4. Select the hamburger menu icon (from the top-left corner of the page), then select “Discover”

    image-20250925-162443.png
  5. From the drop-down menu in the top-left corner of the page, select the data source you want to test your query against

    image-20250925-165923.png
  6. Select “Add Filter” and “Edit as Query DSL”

    image-20250925-175034.png
  7. Remove the existing default braces (curly brackets)

    image-20250925-175248.png
  8. Paste the text you copied from the “RawQuery” portion of the file (in Step #2), then select “Save”

    image-20250926-132307.png
  9. This should should show you the results of your query against whatever data source you selected

    image-20250926-175313.png

Review the results of your query to see if these align with your expectations.

Additional Options:

Adding columns

You can add the specific metadata fields as columns that you would like to see for your results, which may make it easier to review

  • On the left hand side of the page, select the “+” icon next to each of the metadata field names that you would like to display for your query results

    image-20250926-181646.png
  • In the example below, we added the “name”, “parent” and “extension” metadata fields as columns

    image-20250926-181053.png
  • Since our example query above is only looking at “extension” = “log”, all of our results are .log files

  1. Switch data sources

  2. Delete filter

  3. Edit filter

  4. Aggregate pattern

Scenarios and considerations:

Below are some scenarios and considerations when testing out the queries for rules files:

  • Getting a filter/syntax error

  • Getting 0 results

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.