Search code examples
azureazure-cognitive-searchends-with

Azure search: Doesn't give correct results with slashes and solutions given for "ends with" doesn't work


I need to fetch Azure search results from the folderPath field as below: "folderPath": "xxxxxxxxxxxxx_85ba0b45-xxxxx-4d83-a7e6-xxxxxx/abc"

The results should be retrieved only from the above-mentioned folder.

But search service also includes results from folderpaths such as below. "xxxxxxxxxxxxx_85ba0b45-xxxxx-4d83-a7e6-xxxxxx/abc def" and "xxxxxxxxxxxxx_85ba0b45-xxxxx-4d83-a7e6-xxxxxx/abc xyz"

How do I fetch results only from the /abc folderPath?


Solution

  • For this type of scenarios where you want the whole content of the field to match you should use Filters. Filters are documented at https://learn.microsoft.com/en-us/azure/search/search-filters .

    Note that your folderpath field needs to be marked as "Filterable" before you start indexing.

    You will need to specify your filter something like:

    $filter=path eq 'xxxxxxxxxxxxx_85ba0b45-xxxxx-4d83-a7e6-xxxxxx/abc'&querytype=full