Mark
Mark

Reputation: 33

How do you construct an Azure Search query to return a wildcard search based solely on a specific field?

If I may have missed this in some other area of SO please redirect me but I don't think this is a duped question.

I am using Azure Search with an index field called Title which is searchable and filterable using a Standard Lucerne Analyzer.

When using the built-in explorer, if I want to return all Job Titles that are explicitly named Full Stack Developer I can achieve it this way:

$filter=Title eq 'Full Stack Developer'&$count=true 

But if I want to retrieve all the Job Titles using a wildcard to return all records having Full Stack in the name this way:

$filter=Title eq 'Full Stack*'&$count=true 

The first 20 or so records returned are spot on, but after that point I get a mix of records that have absolutely nothing in common with the Title I specified in the query. My initial assumption was that perhaps Azure was including my specified Title performing an inclusive keyword search on the text as well.

Though I found a few instances where that hypothesis seemed to prove out, so many more of the records returned invalidated that altogether.

Maybe I don't understand fully the mechanics under the hood of Azure Search and so though my query appears to be valid; my expectation of the result is way off.

So how should my query look to perform a wildcard resulting to guarantee the words specified in the search to be included in the Titles returned, if this should be possible? And what would be the correct syntax to condition the return to accommodate for OR operators to be inclusive?

Upvotes: 1

Views: 974

Answers (2)

Ben D
Ben D

Reputation: 831

You can use the following syntax to perform a wildcard against a specific field. I am performing two wildcard searches here against two different fields:

queryType=full&search=YourField1Name:(/.*YourSearchForField1.*/) AND YourField2Name:(/.*YourSearchForField2.*/)

Note - the uppercasing of 'AND' is important

Hope that helps (it took me a while to get this working :-))

Upvotes: 0

Gaurav Mantri
Gaurav Mantri

Reputation: 136246

Azure Cognitive Search allows you to perform wildcard searches limited to specific fields only. To do so, you will need to specify the name of the fields in which you want to perform the search in searchFields parameter.

Your search URL in this case would be something like:

https://accountname.search.windows.net/indexes/indexname/docs?api-version=2020-06-30&searchFields=Title&search=Full Stack*

From the link here:

enter image description here

Upvotes: 1

Related Questions