MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.2k stars 21.35k forks source link

Cannot create table indexer that populates the key field with concatenated partition and row keys #107072

Closed omkarkhair closed 1 year ago

omkarkhair commented 1 year ago

We are trying to build an index against a Azure Table Storage and intend to create a Cognitive Search index key using the combination of Partition Key and Row Key.

The Azure documentation here mentions that this is possible by creating a index key field ID and NOT providing any field mapping for this index field. The document mentions ...

https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/search/search-howto-indexing-azure-tables.md#add-search-fields-to-an-index

Create a document key field ("key": true), but allow the indexer to populate it automatically. Do not define a field mapping to alternative unique string field in your table.

A table indexer populates the key field with concatenated partition and row keys from the table. For example, if a row’s PartitionKey is PK1 and RowKey is RK1, then the key value is PK1RK1. If the partition key is null, just the row key is used.

However attempting to create an index and indexer configuration as described leads to the following error.

Data source does not contain column 'ID', which is required because it maps to the document key field 'ID' in the index 'test-index'. Ensure that the 'ID' column is present in the data source, or add a field mapping that maps one of the existing column names to 'ID'. 

Should the table contain a column called ID? If such a column is present, it beats the purpose of using Partition and Row key in combination.

Please let us know if we are misinterpreting the instructions in the document. Thanks in advance.


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Naveenommi-MSFT commented 1 year ago

@omkarkhair Thanks for your feedback! We will investigate and update as appropriate.

HeidiSteen commented 1 year ago

@omkarkhair Thanks for reporting this doc bug. I still need to investigate what happens in Postman and .NET, but what I see in the portal (using Import Data wizard) is that if I leave the key unmapped, the indexer creates a Key field and populates it with a concatenation of partition and row keys. In the example below, I didn't create a Key field, and I didn't set up any field mapping. I'll try Postman next because sometimes the portal adds behaviors that the APIs don't provide inherently.

{
  "@search.score": 1,
  "PartitionKey": "12",
  "RowKey": "12_6B51D431DF5D_tableprojection",
  "Key": "1212_6B51D431DF5D_tableprojection",
  "HotelId": "12",
  "HotelName": "Winter Panorama Resort",
},
HeidiSteen commented 1 year ago

@omkarkhair I confirm that if you're using Postman, create a search field named "Key" (note the case) with "key": true in the field definition. It will be populated on indexer run with concatenated partition and row key values. I updated the docs with this information and those changes will be live in about 4 hours. I'll close this issue because I think it's resolved, but feel free to reopen it if you disagree. You can also post back on this thread with follow up questions (even though the issue is closed).

please-close

omkarkhair commented 1 year ago

Thank you for the help @HeidiSteen! This has helped us make progress.