Querying in Azure AI Search
Azure AI Search supports query constructs for a broad range of scenarios, from free-form text search, to highly specified query patterns, to vector search. All queries execute over a search index that stores searchable content.
Types of queries
Query form | Searchable content | Description |
---|---|---|
full text search | Inverted indexes of tokenized terms. | Full text queries iterate over inverted indexes that are structured for fast scans, where a match can be found in potentially any field, within any number of search documents. Text is analyzed and tokenized for full text search. |
Vector search | Vector indexes of generated embeddings. | Vector queries iterate over vector fields in a search index. |
Hybrid search | All of the above, in a single search index. | Combines text search and vector search in a single query request. Text search works on plain text content in "searchable" and "filterable" fields. Vector search works on content in vector fields. |
Others | Plain text and alphanumeric content. | Raw content, extracted verbatim from source documents, supporting filters and pattern matching queries like geo-spatial search, fuzzy search, and fielded search. |
This article brings focus to the last category: queries that work on plain text and alphanumeric content, extracted intact from original source, used for filters and other specialized query forms.
Autocomplete and suggested queries
Autocomplete or suggested results are alternatives to search
that fire successive query requests based on partial string inputs (after each character) in a search-as-you-type experience. You can use autocomplete
and suggestions
parameter together or separately, as described in this walkthrough, but you can't use them with search
. Both completed terms and suggested queries are derived from index contents. The engine never returns a string or suggestion that is nonexistent in your index. For more information, see Autocomplete (REST API) and Suggestions (REST API).
Filter search
Filters are widely used in apps that are based on Azure AI Search. On application pages, filters are often visualized as facets in link navigation structures for user-directed filtering. Filters are also used internally to expose slices of indexed content. For example, you might initialize a search page using a filter on a product category, or a language if an index contains fields in both English and French.
You might also need filters to invoke a specialized query form, as described in the following table. You can use a filter with an unspecified search (search=*
) or with a query string that includes terms, phrases, operators, and patterns.
Filter scenario | Description |
---|---|
Range filters | In Azure AI Search, range queries are built using the filter parameter. For more information and examples, see Range filter example. |
Faceted navigation | In faceted navigation tree, users can select facets. When backed by filters, search results narrow on each click. Each facet is backed by a filter that excludes documents that no longer match the criteria provided by the facet. |
Note
Text that's used in a filter expression is not analyzed during query processing. The text input is presumed to be a verbatim case-sensitive character pattern that either succeeds or fails on the match. Filter expressions are constructed using OData syntax and passed in a filter
parameter in all filterable fields in your index. For more information, see Filters in Azure AI Search.
Geospatial search
Geospatial search matches on a location's latitude and longitude coordinates for "find near me" or map-based search experience. In Azure AI Search, you can implement geospatial search by following these steps:
- Define a filterable field of one of these types: Edm.GeographyPoint, Collection(Edm.GeographyPoint, Edm.GeographyPolygon).
- Verify the incoming documents include the appropriate coordinates.
- After indexing is complete, build a query that uses a filter and a geo-spatial function.
Geospatial search uses kilometers for distance. Coordinates are specified in this format: (longitude, latitude
).
Here's an example of a filter for geospatial search. This filter finds other Location
fields in the search index that have coordinates within a 300-kilometer radius of the geography point (in this example, Washington D.C.). It returns address information in the result, and includes an optional facets
clause for self-navigation based on location.
POST https://{{searchServiceName}}.search.windows.net/indexes/hotels-vector-quickstart/docs/search?api-version=2024-05-01-preview
{
"count": true,
"search": "*",
"filter": "geo.distance(Location, geography'POINT(-77.03241 38.90166)') le 300",
"facets": [ "Address/StateProvince"],
"select": "HotelId, HotelName, Address/StreetAddress, Address/City, Address/StateProvince",
"top": 7
}
For more information and examples, see Geospatial search example.
Document look-up
In contrast with the previously described query forms, this one retrieves a single search document by ID, with no corresponding index search or scan. Only the one document is requested and returned. When a user selects an item in search results, retrieving the document and populating a details page with fields is a typical response, and a document look-up is the operation that supports it.
Advanced search: fuzzy, wildcard, proximity, regex
An advanced query form depends on the Full Lucene parser and operators that trigger a specific query behavior.
Query type | Usage | Examples and more information |
---|---|---|
Fielded search | search parameter, queryType=full |
Build a composite query expression targeting a single field. Fielded search example |
fuzzy search | search parameter, queryType=full |
Matches on terms having a similar construction or spelling. Fuzzy search example |
proximity search | search parameter, queryType=full |
Finds terms that are near each other in a document. Proximity search example |
term boosting | search parameter, queryType=full |
Ranks a document higher if it contains the boosted term, relative to others that don't. Term boosting example |
regular expression search | search parameter, queryType=full |
Matches based on the contents of a regular expression. Regular expression example |
wildcard or prefix search | search parameter with *~ or ? , queryType=full |
Matches based on a prefix and tilde (~ ) or single character (? ). Wildcard search example |
Next steps
For a closer look at query implementation, review the examples for each syntax. If you're new to full text search, a closer look at what the query engine does might be an equally good choice.
Atsiliepimai
https://aka.ms/ContentUserFeedback.
Jau greitai: 2024 m. palaipsniui atsisakysime „GitHub“ problemų, kaip turiniui taikomo atsiliepimų mechanizmo, ir pakeisime jį nauja atsiliepimų sistema. Daugiau informacijos žr.Pateikti ir peržiūrėti atsiliepimą, skirtą