Blog

Relevance Search API

– 4 Minutes

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
Parameter Required? Example
api-version Yes 9.0
search No Microsoft
searchEntities No product
facet No (@search.entityname,count:100),(product.price,interval:100)
$top No 1
$skip No 50
$filter No product:price gt 100
$count No true

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 about configuring searchable fields.

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 Service API. 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

Gilad

Can you add an example for rest api to search documents.
For example we have on dynamics 365 on line a table of documents that contain approximately 1 millions records. We need to search records according to the field “docName”. Let’s say to search all records that docName contain the word “letter” and “client”. How can we do that? Using regular search with operator like and % takes 30 seconds which is to much time.
Thanks.

Gilad

Can you add an example for rest api to search documents.
For example we have on dynamics 365 on line a table of documents that contain approximately 1 millions records. We need to search records according to the field “docName”. Let’s say to search all records that docName contain the word “letter” and “client”. How can we do that? Using regular search with operator like and % takes 30 seconds which is to much time.
Thanks.

VALERY

Please find example
GET https://ORG.crm.dynamics.com/api/search/indexes/default/Entities?api-version=9.0&search=pro&searchEntities=product

Phil Cole

This is now GA:
https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/relevance-search