Search code examples
azure-cognitive-search

Best way to query documents with a list of tags


I have an index which has a field that is a string collection, which contains a list of tags.

Does anyone know the most efficient way to query the index, with a list of tags to match against the tags string collection?

This is a very inefficient example of what I am trying to do: /indexes/instruments/docs?api-version=2014-07-31-Preview&$top=10&$skip=0&$count=true&search=*&$filter=universes/any(t: t eq 'U') or universes/any(t: t eq 'B') or universes/any(t: t eq 'E')

In this example the tags field is "universes". The problem is that I need to filter on as many as 30 tags, so this query seems terrible!


Solution

  • This is the right way to express this query. It does look long syntactically but it should run fine from the efficiency perspective. What will dominate response time is not so much the number of terms here (at least in the order of magnitude you mentioned) but how big the matching set is.

    10/16/2017 update: note that Azure Search now has a new filter function, search.in(), that provides a more compact representation and faster execution for queries like this. More details and API version requirements here: https://learn.microsoft.com/en-us/rest/api/searchservice/odata-expression-syntax-for-azure-search