azure-devopsazure-devops-rest-apicode-search

Syntax of "filter" param in Azure Code Search API


The Azure Code Search API defines the request body param filter as such :

filters 
object

Filters to be applied. Set it to null if there are no filters to be applied.

and provides a single example as well :

POST https://almsearch.dev.azure.com/fabrikam/_apis/search/codesearchresults?api-version=7.0

{
  "searchText": "CodeSearchController",
  "$skip": 0,
  "$top": 1,
  "filters": {
    "Project": [
      "MyFirstProject"
    ],
    "Repository": [
      "MyFirstProject"
    ],
    "Path": [
      "/"
    ],
    "Branch": [
      "master"
    ],
    "CodeElement": [
      "def",
      "class"
    ]
  },
  "$orderBy": [
    {
      "field": "filename",
      "sortOrder": "ASC"
    }
  ],
  "includeFacets": true
}

I can't find the exhaustive syntax of said filter param. Can anyone point me in the right direction by any chance?

Thanks!


Solution

  • The specific syntax for the filter parameter isn't exhaustively documented in the Azure Code Search API reference. You can check similar ticket.

    You may follow the given example to structure the request body, including the filters object. Or actually you can also find the api in network trace(F12) with detail request body.

    enter image description here

    To search all repositories that contain Kotlin files, you can skip filter, search ext:kt as below, simply copy the request body to rest api.

    enter image description here