How can I use AzureSearch with wildcard
Asked Answered
G

2

5

I want to search for a field that has the name "14009-00080300", and I want to get a hit when searching only on a part of that, for example "14009-000803".

Using this code I dont get any hits:

   {
 "search": "\"14009-000803\"*",
 "count":true,
 "top":10
}

Is there a way to use azure search like SQL uses its wildcard search? (select * from table where col like '%abc%' ?

Gehrke answered 1/12, 2017 at 10:42 Comment(0)
C
8

You can get your desired result by performing a full query with Lucene syntax (as noted by Sumanth BM). The trick is to do a regex search. Modify your query params like so:

{
 "queryType": "full",
 "search": "/.*searchterm.*/",
 "count":true,
 "top":10
}

Replace 'searchterm' with what you are looking for and azure search should return all matches from your index searchable columns.

See Doc section: MS Docs on Lucene regular expression search

Cide answered 26/1, 2018 at 9:43 Comment(0)
G
1

You can use generally recognized syntax for multiple () or single (?) character wildcard searches. Note the Lucene query parser supports the use of these symbols with a single term, and not a phrase. For example to find documents containing the words with the prefix "note", such as "notebook" or "notepad", specify "note".

Note You cannot use a * or ? symbol as the first character of a search. No text analysis is performed on wildcard search queries. At query time, wildcard query terms are compared against analyzed terms in the search index and expanded.

SearchMode parameter considerations The impact of searchMode on queries, as described in Simple query syntax in Azure Search, applies equally to the Lucene query syntax. Namely, searchMode in conjunction with NOT operators can result in query outcomes that might seem unusual if you aren't clear on the implications of how you set the parameter. If you retain the default, searchMode=any, and use a NOT operator, the operation is computed as an OR action, such that "New York" NOT "Seattle" returns all cities that are not Seattle.

https://learn.microsoft.com/en-us/rest/api/searchservice/simple-query-syntax-in-azure-search

Reference: https://learn.microsoft.com/en-us/rest/api/searchservice/lucene-query-syntax-in-azure-search#bkmk_wildcard

Gaffe answered 1/12, 2017 at 18:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.