Relevance Search in Dynamics 365 is built on top of Azure Search, but since Microsoft manages the service for us on the back-end, we can't use the standard REST API to access it.  However, there is an undocumented wrapper endpoint in Dynamics 365 that we can use which functions essentially the same as the Azure Search API!

Disclaimer: this is unsupported as there is no official documentation - it is provided for informational purposes only.

In order to use this endpoint, you must first have Relevance Search enabled.  You can do this by going to Settings > Administration > System Settings, and enabling it on the General tab.  Once you enable it, you will have to wait a little bit for the data to get synced over to Azure.

Once Relevance Search is ready, you can submit requests to the API!

GET  https://organization.crm.dynamics.com/api/search/indexes/default/Entities
ParameterRequired?Example
api-versionYes9.0
searchNoMicrosoft
searchEntitiesNoproduct
facetNo(@search.entityname,count:100),(product.price,interval:100)
$topNo1
$skipNo50
$filterNoproduct:price gt 100
$countNotrue

Executing this request would return a response similar to this:

{
  "@odata.count": 100,
  "@search.fullsyncinprogress": false,
  "value": [
    {
      "@search.score": 2.9922318,
      "@search.highlights": {
        "name": [
          "{crmhit}Microsoft{/crmhit} Dynamics 365"
        ],
        "vendorname": [
          "{crmhit}Microsoft{/crmhit}"
        ]
      },
      "@search.entityname": "product",
      "@search.objectid": "00000000-0000-0000-0000-000000000000",
      "@search.objecttypecode": 1024,
      "name": "Microsoft Dynamics 365",
      "productnumber": "MSDYN365",
      "price": 195,
      "vendorname": "Microsoft"
    }
  ],
  "facets": {
    "@search.entityname": [
      {
        "Type": "Value",
        "Value": "product",
        "Count": 100
      }
    ],
    "product.price": [
      {
        "Type": "Value",
        "Value": 100,
        "Count": 40
      },
      {
        "Type": "Value",
        "Value": 200,
        "Count": 60
      }
    ]
  },
  "warnings": [],
  "errors": []
}

If you are executing this outside of Dynamics 365, you can pass in an Authorization header with the Bearer/OAuth token that has access to your Dynamics 365 resource.  You can alter the fields returned in the response (i.e. facetable/filterable fields) by adding View Columns to the Quick Find view.  Similarly, you can alter the searchable fields by adding Find Columns to the Quick Find view.  See more here.

As far as I can tell, the API limits introduced in March do not apply to this endpoint.

You can find more documentation on the Azure Search Servicie API here.  Note: this documentation talks about other parameters that do not appear to work through the Dynamics 365 wrapper, but it does cover facets and filters in more detail.

Comments