azure-cognitive-searchazure-search-.net-sdk

Filtering based on metadata_storage_path Azure Search


I want to filter results based on a specific path for example "/container/folder1", however I am using metadata_storage_path as my document key hence it is encrypted as base64 by default.
I have tried to create the filter based on the encrypted value but that doesn't seem to work, example "filter": "metadata_storage_path eq 'aHR0cHM6Ly9hemRdasb2IuYmxvYi5jb3JdpbmRvd3sL3NlYXJjaddkZXIsad=='",. I suppose it's because of the special characters that the base64encoded path contains. Is there a way to filter based on this base 64 encoded metadata path ? I have also tried using the base64decode function, and mapping the metadata storage path to a decoded field using fieldmapping but it returns an error every time I re-run the indexer, looks like the document key cannot actually be decoded. Any help would be appreciated.

Errors I get when using the base64decode function.

'metadata_storage_path': The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. '

Solution

  • From the error message , you should check if the length of base64string is a multiple of 4 and the base64string is valid .

    A Base64 string will only be composed of characters 'A'..'Z', 'a'..'z', '0'..'9', '+', '/' and it is often padded at the end with up to two '=', to make the length a multiple of 4.

    Your original base64string length is 62, not a multiple of 4, you should delete the last two "=" padding character to make the base64string valid .