question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Azure Search][QUERY] The request is invalid while trying to update search index from a Cosmos DB Trigger

See original GitHub issue

Query/Question I want to update a search index inside a Cosmos Db Trigger. I am doing this so far.

[FunctionName("SearchIndexUpdate")]
public async Task Run([CosmosDBTrigger(
	databaseName: "%DatabaseName%",
	collectionName: "%CollectionName%",
	ConnectionStringSetting = "Connection",
	LeaseCollectionName = "%LeaseCollectionName%",
	CreateLeaseCollectionIfNotExists = true)]IReadOnlyList<Document> changedDocuments)
{
	if (changedDocuments != null && changedDocuments.Count > 0)
	{
		IndexBatch<Microsoft.Azure.Documents.Document> batch = Microsoft.Azure.Search.Models.IndexBatch.MergeOrUpload(changedDocuments);
		DocumentIndexResult documentIndexResult;
		try
		{
			await searchIndexClient.Documents.IndexAsync(batch).ConfigureAwait(false);
		}
		catch (Exception)
		{
			throw;
		}
	}
}

I am injecting searchIndexClient from Startup.cs

public class Startup : IWebJobsStartup
{

	public void Configure(IWebJobsBuilder builder)
	{
		searchCredentials = new SearchCredentials(Environment.GetEnvironmentVariable("SearchAdminKey"));

		ISearchIndexClient searchIndexClient = new SearchIndexClient(
			Environment.GetEnvironmentVariable("SearchServiceName"),
			Environment.GetEnvironmentVariable("SearchIndexName"),
			searchCredentials);
		builder.Services.AddSingleton(searchIndexClient);
	}
}

I get the exception when its trying to do the IndexAsync operation:

 System.Private.CoreLib: Exception while executing function: SearchIndexUpdate. 
Microsoft.Azure.Search.Data: The request is invalid. Details: parameters : A resource without a 
type name was found, but no expected type was specified. To allow entries without type 
information, the expected type must also be specified when the model is specified.

What am I doing wrong here?

Here is the type of document I have inside Cosmos DB collection.

{
    "custID": "testCustId",
    "crpID": "TestCRP1",
    "Name": "abcd",
    "Number": "21423423Update",
    "Contact": {
        "firstName": "sdfsdfsdf",
        "lastName": "sfsdfsdfsd",
        "phoneNumber": "213123213",
        "email": "sdfsdfsd@gmail.com"
    },
    "id": "cXXpo0997dee-5bf3-445e-bf4c-bd1599979431",
    "modifiedBy": "UserId",
    "modifiedDate": "2019-09-25T13:42:12.7261652Z",
    "isDeleted": false,
    "_rid": "anYwAMjmX1koAAAAAAAAAA==",
    "_self": "dbs/anYwAA==/colls/anYwAMjmX1k=/docs/anYwAMjmX1koAAAAAAAAAA==/",
    "_etag": "\"2700e96e-0000-0100-0000-5d8bde590000\"",
    "_attachments": "attachments/",
    "_ts": 1569447513
}

Why is this not a Bug or a feature Request? I am trying to find out appropriate usage of MergeOrUpload and Documents.IndexAsync methods inside a Cosmos DB Trigger. There is no search result for this issue so far.

Setup (please complete the following information if applicable):

  • OS: Windows
  • IDE : Visual Studio
  • Version of the Library used: Azure.Search.Service 10.0.0

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Query Added
  • Setup information Added

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
anmshcommented, Nov 18, 2019

Thank you @brjohnstmsft the resolution has helped. Field mappings were not matching exactly and that has caused the issue.

1reaction
brjohnstmsftcommented, Sep 26, 2019

I see a few discrepancies between your index schema and the data you’re trying to index:

  • Field names in Azure Search are case-sensitive, but several fields have different case between the schema and the data. For example, CRPID.
  • Azure Search will reject fields that aren’t declared in the index definition. For example, the email sub-field of Contact is missing.

This probably explains the (unfortunately cryptic) error message you’re seeing. Once you ensure your data matches the index definition, please let me know if it solves the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot issues with the Azure Functions trigger for ...
This article discusses common issues, workarounds, and diagnostic steps when you're using the Azure Functions trigger for Azure Cosmos DB.
Read more >
Unable to update the cosmosDB collection from Azure ...
I have an Azure cosmosDB trigger function which is configured the above collection as output. Below is the index.js file which i am...
Read more >
Measure index performance in Azure Cosmos DB SQL API
... Optimize an Azure Cosmos DB SQL API container's index policy for a specific query ​ 1:06:14 - Knowledge Check ​ 1:11:18 -...
Read more >
Azure Cosmos DB 4xx Status Codes
An Unauthorized request means the Authorization header for the request is invalid. This can be caused by issues with the client that is...
Read more >
What is throttled search query in azure search?
Azure Search starts throttling requests when the error rate (requests failing with 207 or 503 status codes) exceeds a certain threshold.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found