0

How do you structure a Azure POST REST call to match a value on a comma-separated list string?

For Example:
I want to search for "GWLAS" or "SAMGV" within the Azure field "ProductCategory".

The "ProductCategory" field in the documents will have a comma-separated value string such as "GWLAS, EXDEB, SAMGV, AMLKYC".


Any ideas?

jbrekke
  • 88
  • 6

1 Answers1

2

If you use the default analyzer for your ProductCategory field (assuming it is searchable), it should word-break on commas by default. This means all you should need to do is search for the terms you're interested in and limit it to the right field:

POST /indexes/yourindex/docs/search?api-version=2016-09-01

{
    "search": "GWLAS SAMGV",
    "searchFields": [ "ProductCategory" ]
}

There are other ways to do this, but this is the simplest. If you already scope parts of your search query to other fields, here is how you can scope just the desired terms to ProductCategory:

POST /indexes/yourindex/docs/search?api-version=2016-09-01

{
    "search": "(Name:\"Anderson John\"~3 OR Text:\"Anderson John\"~3) AND ProductCategory:GWLAS SAMGV",
    "queryType": "full"
}

Please consult the Azure Search REST API documentation for details on other options you can set in the Search request. Also, this article will help you understand how Azure Search executes queries. You can find the reference for the full Lucene query syntax here.

Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42
  • How would I isolate the search value on "ProductCategory" if I have additional field-specific values already in the search parameter? My current search parameter is "search":"Name:\"Anderson John\"~3 OR Text:\"Anderson John\"~3". – jbrekke Apr 21 '17 at 21:45
  • I edited my answer to address your specific scenario. Please check out the documentation on the full Lucene syntax if you haven't already (link in the answer). – Bruce Johnston Apr 24 '17 at 19:45
  • @BruceJohnston when you mention the "Default Analyzer" are you referring to Standard - Lucene, or English - Microsoft? – Stpete111 Apr 24 '17 at 22:41
  • @Stpete111 Standard - Lucene is the default. Other analyzers likely also have this behavior; I was just assuming you're using the default because you didn't specify otherwise. – Bruce Johnston Apr 25 '17 at 00:49
  • Thanks, yes we are using Lucene. But the reason I was confused is because I watched a video on Azure Search yesterday where the instructor mentions that English - Microsoft is technically the "default" analyzer (even though when you create an index, it "defaults" to Lucene if you don't specify otherwise. – Stpete111 Apr 25 '17 at 01:20
  • @Stpete111@jbrekke If you guys find this answer helpful, please mark it as accepted. Thanks! – Bruce Johnston Apr 25 '17 at 17:51
  • Hi Bruce, I definitely will, just need to test it first. We are currently rewriting all our records after which point, if it works (I'm sure it will) I'll mark the answer as accepted. Thanks. – Stpete111 Apr 25 '17 at 18:15