Managing Search API Query Conditions
Who is this article for?
Users who need to search records that meet a variety of requirements and assist with populating data repositories
Restricted access to Users with interface development roles. It is a read-only HTTP/JSON API.
Search API allows for two distinct types of query conditions: compound conditions and simple conditions. Both types adhere to a consistent formatting structure, ensuring clarity and uniformity when constructing queries.
A compound condition is characterized by its inclusion of multiple simple conditions. This allows for a more complex query that can evaluate several criteria simultaneously. For instance, if you are searching for records that meet a variety of requirements, a compound condition enables you to combine these simple conditions into a cohesive query.
Simple conditions are standalone and cannot incorporate compound conditions within them.
This distinction is crucial for users to understand how to effectively utilize the Search API and construct precise queries that yield the desired results.
Compound Conditions
Compound conditions have three parameters. condition, query and not. These are conditions that will check multiple simple conditions to return the desired data. These are either an "AND" or an "OR" condition. These conditions will contain a list of query conditions to match against.
| Parameter | Required | Specific Values | Default Value | Details |
|---|---|---|---|---|
condition |
Yes | "AND" or "OR" | "EQUALS" | AND or OR must be set to create a compound query condition. |
query |
Yes | List of Simple Conditions | NULL | This will be a list of simple or compound conditions to match |
not |
No | true/false | false | Whether or not to return what is matched by the simple conditions or everything that doesn't match the Conditions |
Compound conditions example:
{
"query": {
"condition": "AND",
"query": [
{
"condition": "equals",
"field": "fieldA",
"term": [
"matchMe"
]
},
{
"condition": "equals",
"field": "fieldB",
"term": [
"matchMeToo"
]
}
]
}
}
Simple Conditions
Simple conditions control what type of "conditions" must be met for the data to be returned. Not all conditions will require all parameters to be set, and not all parameters are required.
| Parameter | Required | Specific Values | Default Value | Details |
|---|---|---|---|---|
condition |
Yes | *See Available Conditions Table | "EQUALS" | The defined condition to check for. there are multiple possibilities for this but if not included it will default to an equal's check |
type |
No | *See Query Types Table | "DEFAULT" | The type of query to execute. Diverse types will query against different values depending on the field |
not |
No | true/false | false | Whether or not to do the inverse match. Not will match if this condition is not met |
field |
Yes | the field name you want to check the value of | NULL | The field you would like to check the value of. can be referenced by name or field code or sub code |
term |
Not always | Any value you want to match | NULL | This is an array of values. Some operators will handle this value differently and what can be put into the field. It will accept a String as a single value for the array |
highlight |
No | true/false | false | Will add this to the list of fields to add highlighting to when searching |
boost |
No | 0 - 100 | NULL | This will add boosting to a field match to move it up the list of relevant search results. |
Simple conditions example:
//find all that have "matchMe" for the value in "fieldA"
{
"query": {
"condition": "equals",
"field": "fieldA",
"term": [
"matchMe"
]
}
}
//find all that have a version between 1 and 10
{
"query": {
"condition": "between",
"field": "version",
"term": [
1,
10
]
}
}
//find all that have a date in today's date
{
"query": {
"condition": "today",
"field": "date"
}
}
//find where the assigned field is empty or missing
{
"query": {
"condition": "empty",
"field": "_assigned"
}
}
Available Conditions
key: term(#) = the number of expected term values. term(S) = can have any number of terms to match against.
| Condition | Condition Type | Required Parameters | Expected Value Type | Description |
|---|---|---|---|---|
| AND | Compound | query | List of Simple or Compound Conditions | AND condition that requires all the listed conditions to be true for it to match |
| OR | Compound | query | List of Simple or Compound Conditions | OR condition that requires at least one of the listed conditions to be true for it to match |
| EQUALS | Simple | field,term(s) | Any value | Will check the field for the value specified |
| NOT_EQUALS | Simple | field,term(s) | Any value | Will match on those that don't have the value specified in the field |
| EQUALS_STRING | Simple | field,term(s) | Any value | Will check the field for the value specified |
| EMPTY | Simple | field | NONE | Will check to see if the field is either missing or does not contain anything in it |
| NOT_EMPTY | Simple | field | NONE | Will check to see if the field exists and contains something in it |
| BELOW | Simple | field,term(1) | the object to check below in a hierarchy (either ID or value) | Will perform a search to find the hierarchy value that matches and then return anything that is below this value in the hierarchy |
| AT_OR_BELOW | Simple | field,term(1) | the object to check at or below in a hierarchy (either ID or value) | Same as below but will include matches that are at the value instead of just those below it |
| BETWEEN | Simple | field,term(2) | Any value | This will attempt to do a range search to find values between the two given terms. Such as dates and numbers |
| TODAY | Simple | field | NONE | Will create a date for today and check the specified field to see if it matches |
| YESTERDAY | Simple | field | NONE | Will create a date for yesterday and check the specified field to see if it matches |
| TOMORROW | Simple | field | NONE | Will create a date for tomorrow and check the specified field to see if it matches |
| THIS_WEEK | Simple | field | NONE | Will create a date for Sunday and Saturday for this week. Then perform a Between check of these two values on the field specified |
| THIS_MONTH | Simple | field | NONE | Will create a date for the first and last day of this month. Then perform a Between check of these two values on the field specified |
| THIS_QUARTER | Simple | field | NONE | Will create a date for the first day of the first month and the last day of the last month for the quarter we are in. Then perform a Between check of these two values on the field specified ( Q1=Jan-Mar, Q2=Apr-Jun, Q3=Jul-Sept Q4=Oct-Dec ) |
| THIS_YEAR | Simple | field | NONE | Will create a date for the first day and the last day of this year. Then perform a Between check of these two values on the field specified |
| LAST_WEEK | Simple | field | NONE | Will create a date for Sunday and Saturday for last week. Then perform a Between check of these two values on the field specified |
| LAST_MONTH | Simple | field | NONE | Will create a date for the first day and the last day for the month before. Then perform a Between check of these two values on the field specified |
| LAST_QUARTER | Simple | field | NONE | Will create a date for the first day of the first month, and the last day of the last month for the quarter before the current quarter. Then perform a Between check of these two values on the field specified |
| LAST_YEAR | Simple | field | NONE | Will create a date for the first day of the first month, and the last day of the last month for the previous year. Then perform a Between check of these two values on the field specified |
| NEXT_WEEK | Simple | field | NONE | Will create a date for Sunday and Saturday for next week. Then perform a Between check of these two values on the field specified |
| NEXT_MONTH | Simple | field | NONE | Will create a date for the first day and the last day for the next month. Then perform a Between check of these two values on the field specified |
| NEXT_QUARTER | Simple | field | NONE | Will create a date for the first day of the first month, and the last day of the last month for the quarter after the current quarter. Then perform a Between check of these two values on the field specified |
| NEXT_YEAR | Simple | field | NONE | Will create a date for the first day of the first month, and the last day of the last month for next year. Then perform a Between check of these two values on the field specified |
| LAST_7_DAYS | Simple | field | NONE | Will create a date for Today - 7 and Today. Then perform a Between check of these two values on the field specified |
| LAST_30_DAYS | Simple | field | NONE | Will create a date for Today - 30 and Today. Then perform a Between check of these two values on the field specified |
| LAST_60_DAYS | Simple | field | NONE | Will create a date for Today - 60 and Today. Then perform a Between check of these two values on the field specified |
| LAST_90_DAYS | Simple | field | NONE | Will create a date for Today - 90 and Today. Then perform a Between check of these two values on the field specified |
| LAST_120_DAYS | Simple | field | NONE | Will create a date for Today - 120 and Today. Then perform a Between check of these two values on the field specified |
| LAST_365_DAYS | Simple | field | NONE | Will create a date for Today - 365 and Today. Then perform a Between check of these two values on the field specified |
| NEXT_7_DAYS | Simple | field | NONE | Will create a date for Today and Today + 7. Then perform a Between check of these two values on the field specified |
| NEXT_30_DAYS | Simple | field | NONE | Will create a date for Today and Today + 30. Then perform a Between check of these two values on the field specified |
| NEXT_60_DAYS | Simple | field | NONE | Will create a date for Today and Today + 60. Then perform a Between check of these two values on the field specified |
| NEXT_90_DAYS | Simple | field | NONE | Will create a date for Today and Today + 90. Then perform a Between check of these two values on the field specified |
| NEXT_120_DAYS | Simple | field | NONE | Will create a date for Today and Today + 120. Then perform a Between check of these two values on the field specified |
| NEXT_365_DAYS | Simple | field | NONE | Will create a date for Today and Today + 365. Then perform a Between check of these two values on the field specified |
| BEFORE_TODAY | Simple | field | NONE | Will create a date for the start of time and Today - 1. Then perform a Between check of these two values on the field specified |
| TODAY_OR_BEFORE | Simple | field | NONE | Will create a date for the start of time and Today. Then perform a Between check of these two values on the field specified |
| AFTER_TODAY | Simple | field | NONE | Will create a date for Today + 1 and the end of time. Then perform a Between check of these two values on the field specified |
| TODAY_OR_AFTER | Simple | field | NONE | Will create a date for Today and the end of time. Then perform a Between check of these two values on the field specified |
| GREATER_THAN | Simple | field,term(1) | date/number | Will check for values greater than the term |
| LESS_THAN | Simple | field,term(1) | date/number | Will check for values less than the term |
| GREATER_THAN_EQUAL_TO | Simple | field,term(1) | date/number | Will check for values greater than or equal to the term |
| LESS_THAN_EQUAL_TO | Simple | field,term(1) | date/number | Will check for values less than or equal to the term |
Query Types
| Type | Behavior |
|---|---|
DEFAULT |
No special handling. will query against the raw field. for picklist P_#, Reference R_#, and User U_# fields |
MEANING |
Will search against the value field, most fields will have no change. for picklist P_MEANING#, Reference R_VALUE#, and User U_NAME# fields |
STRICT |
Will search against the strict field if present and wraps the term in quotes to treat the entire term as a single value. CSSTRICT_#, CLSTRICT_1 etc. |
ID |
Applies to Reference field searches. Will cause the search to execute against the "Identifier" field. ex. R_IDENTIFIER# |
CODE |
Will Search the Code Field of applicable fields. applicable fields include RA, BY, WF_TASK, WF_STEP, LAST_UPDATED_BY |