Power Apps Search Series : Querying Dataverse with Full-Text Search

In the previous post, we introduced Dataverse Search and when to use it over traditional query methods. Now let’s roll up our sleeves and get hands-on with the Query API, which allows you to programmatically search Dataverse data using full-text, relevance-based search.


What Is the Query API?

The Dataverse Search Query API allows developers to perform full-text searches across indexed tables and columns using REST-based or SDK-based methods.

You can pass a search term and get ranked results that match across multiple entities, fields, and even partial words.


Sample API Request

Here’s a typical API call to search for “Contoso” in your Dataverse environment:

POST https://<env>.crm.dynamics.com/api/search/v1.0/query HTTP/1.1
Authorization: Bearer eyJ0eXAi...
Content-Type: application/json

{
  "searchTerm": "Contoso",
  "entities": [
    {
      "name": "account"
    },
    {
      "name": "contact"
    }
  ]
}

This request searches across account and contact tables for anything matching “Contoso” in a searchable field.


Response Explained

Here’s a simplified version of a sample response:

{
  "value": [
    {
      "entityName": "account",
      "entityId": "12345...",
      "score": 5.67,
      "highlightedFields": [
        {
          "fieldName": "name",
          "fieldValue": "<em>Contoso</em> Ltd."
        }
      ],
      "document": {
        "name": "Contoso Ltd.",
        "accountnumber": "A12345"
      }
    },
    ...
  ]
}

Key Response Fields

FieldDescription
entityNameLogical name of the table where the result was found
entityIdGUID of the matched record
scoreRelevance score (higher = stronger match)
highlightedFieldsShows matched fields with HTML tags to highlight search hits
documentFull set of selected fields for the record

This makes it ideal for building responsive search experiences where the most relevant data is surfaced first.


Advanced Query Options

Entity Filters

"entities": [
  {
    "name": "account",
    "filter": "statecode eq 0"
  }
]

You can limit results to records that match certain OData filter expressions (e.g., only Active records).

Paging

"pagingInfo": {
  "pageNumber": 1,
  "count": 10
}

Paginate through results efficiently.

Facets (Aggregation)

"facets": [
  {
    "field": "customertypecode"
  }
]

Get grouped counts (e.g., number of matches per customer type).


When to Use the Search Query API

ScenarioRecommended?
Keyword-driven record lookup✅ Yes
Filter contacts by city = ‘Berlin’❌ Use FetchXML
Autocomplete input field❌ Use Suggest API (next post)
Find all leads with similar names✅ Yes

SDK Usage Example

In C# (via Dataverse SDK):

var request = new SearchQueryRequest
{
    SearchTerm = "Contoso",
    Entities = new List<EntityQuery>()
    {
        new EntityQuery("account"),
        new EntityQuery("contact")
    }
};
var response = (SearchQueryResponse)service.Execute(request);
foreach (var result in response.Results)
{
    Console.WriteLine($"{result.EntityName} - {result.Document["name"]}");
}

Leave a comment