[Azure Search][QUERY] The request is invalid while trying to update search index from a Cosmos DB Trigger
See original GitHub issueQuery/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:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Thank you @brjohnstmsft the resolution has helped. Field mappings were not matching exactly and that has caused the issue.
I see a few discrepancies between your index schema and the data you’re trying to index:
CRPID
.email
sub-field ofContact
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.