跳转到内容

搜索条件

搜索条件可用于根据特定条件检索实体的列表响应。以下是一些搜索条件示例。

字段

field 指构建条件的输入实体字段。

示例

{
  "field": "created_time",
  "condition": "greater than",
  "value": "1488451440000"
}

条件

条件是构建条件的运算符。

支持的条件

描述 运算符 运算符简写
等于 =, eq
不等于 不是 !=, neq
大于 大于 gt
大于等于 大于或等于 gte
小于 小于 lt
小于等于 小于或等于 lte
范围 介于
不在范围内 不介于
以...开始 以...开始
以...结束 以...结束
包含 包含
不包含 不包含

示例

{
  "field": "created_time",
  "condition": "greater than",
  "value": "1488451440000"
}

In the above example the greater than is the operator which refers to greater than symbol (>).

Comparison – (field > value)

值/值集合

值字段中提供的值取决于字段名称的数据类型和条件中使用的操作符。

  1. 如果是多个值,需使用 values 键。
  2. 如果是单个值,需使用 value 键。

示例(值)

{
  "field": "created_time",
  "condition": "greater than",
  "value": "1488451440000"
}

上述示例中,条件的值是基于字段 created_time 的 Long 类型。

示例(值数组)

{
  "field": "group.name",
  "condition": "is",
  "values": [
    "Network",
    "Printer Problem"
  ]
}

上述示例中,条件的可能值是数组内提到的 Network 和 Printer Problem。

子项

children 条件键包含子条件或嵌套条件。

示例

{
  "list_info": {
    "row_count": 100,
    "search_criteria": {
      "field": "status",
      "condition": "is",
      "value": {
        "id": "100000000000008033",
        "name": "Open"
      },
      "children": [
        {
          "field": "created_time",
          "condition": "greater than",
          "value": "1488451440000",
          "logical_operator": "AND"
        }
      ]
    }
  }
}

上述搜索条件的条件规则如下,
Criteria – (status = 'Open' AND (created_time > 1488451440000))

1) A&B – A(且)B

以下 list info 对象将检索组“Network”下所有待处理的请求。

{
  "list_info": {
    "row_count": 15,
    "search_criteria": [
      {
        "field": "group.name",
        "condition": "is",
        "values": [
          "Network"
        ]
      },
      {
        "field": "status.in_progress",
        "condition": "is",
        "logical_operator": "and",
        "values": [
          true
        ]
      }
    ]
  }
}

以下 list info 对象将检索组“Network”下所有“Open”状态的请求。

{
  "list_info": {
    "row_count": 15,
    "search_criteria": [
      {
        "field": "group.name",
        "condition": "is",
        "values": [
          "Network"
        ]
      },
      {
        "field": "status.internal_name",
        "condition": "is",
        "logical_operator": "and",
        "values": [
          "Open"
        ]
      }
    ]
  }
}

2) A&B&(C&D) - A(且)B(且)[C(且)D]

以下 list info 对象将检索组“Network”下今天创建的所有“Open”状态请求。

{
  "list_info": {
    "row_count": 15,
    "search_criteria": [
      {
        "field": "group.name",
        "condition": "is",
        "values": [
          "Network"
        ]
      },
      {
        "field": "status.internal_name",
        "condition": "is",
        "logical_operator": "and",
        "values": [
          "Open"
        ]
      },
      {
        "field": "created_time",
        "condition": "greater than",
        "logical_operator": "and",
        "values": [
          "1553731200000"
        ],
        "children": [
          {
            "field": "created_time",
            "condition": "lesser than",
            "logical_operator": "and",
            "values": [
              "1553817599000"
            ]
          }
        ]
      }
    ]
  }
}

3)(AB)&(CD) – [A(或)B]且[C(或)D]

{
  "list_info": {
    "row_count": 15,
    "search_criteria": [
      {
        "field": "status.in_progress",
        "condition": "is",
        "values": [
          true
        ],
        "logical_operator": "AND",
        "children": [
          {
            "field": "status.internal_name",
            "condition": "is",
            "values": [
              "Resolved"
            ],
            "logical_operator": "OR"
          }
        ]
      },
      {
        "field": "priority.name",
        "condition": "is",
        "logical_operator": "AND",
        "values": [
          "High"
        ],
        "children": [
          {
            "field": "urgency.name",
            "condition": "is",
            "values": [
              "Urgent"
            ],
            "logical_operator": "OR"
          }
        ]
      }
    ]
  }
}

以下是更多搜索条件的示例。

以下将检索所有在一段时间后创建的打开状态请求。

{
  "list_info": {
    "row_count": 100,
    "search_criteria": {
      "field": "status",
      "condition": "is",
      "value": {
        "id": "100000000000008033",
        "name": "Open"
      },
      "children": [
        {
          "field": "created_time",
          "condition": "greater than",
          "value": "1488451440000",
          "logical_operator": "AND"
        }
      ]
    }
  }
}

以下将检索所有符合以下条件的打开状态请求:created_time 大于某段时间且 subject 必须以特定值开头。

{
  "list_info": {
    "row_count": 100,
    "search_criteria": {
      "field": "status",
      "condition": "is",
      "values": [
        {
          "id": "100000000000008033",
          "name": "Open"
        }
      ],
      "children": [
        {
          "field": "created_time",
          "condition": "greater than",
          "values": [
            {
              "value": "1488451440000",
              "display_value": "02 Mar 2017, 16:14:00"
            }
          ],
          "logical_operator": "AND"
        },
        {
          "field": "subject",
          "condition": "starts with",
          "values": [
            "quick"
          ],
          "logical_operator": "OR"
        }
      ]
    }
  }
}

以下 listinfo 对象将检索符合条件的请求。

((状态为 open) 且 (创建时间大于 或 subject 以“quick”开头)) 或 (组不是 network 且 技术人员非空)

{
  "list_info": {
    "row_count": 100,
    "search_criteria": [
      {
        "field": "status",
        "condition": "is",
        "values": [
          {
            "id": "100000000000008033",
            "name": "Open"
          }
        ],
        "logical_operator": "AND",
        "children": [
          {
            "field": "created_time",
            "condition": "greater than",
            "values": [
              {
                "value": "1488451440000",
                "display_value": "02 Mar 2017, 16:14:00"
              }
            ],
            "logical_operator": "AND"
          },
          {
            "field": "subject",
            "condition": "starts with",
            "values": [
              "quick"
            ],
            "logical_operator": "OR"
          }
        ]
      },
      {
        "field": "group",
        "condition": "is not",
        "values": [
          {
            "id": "100000000000008057",
            "name": "Network"
          }
        ],
        "logical_operator": "OR",
        "children": [
          {
            "field": "technician",
            "condition": "is not",
            "logical_operator": "AND"
          }
        ]
      }
    ]
  }
}