AI-102 Question 379
Single answerYou are designing a search functionality for a customer-facing application using Azure Cognitive Search. The index contains a field named 'ProductName' and another field named 'Price'. You are tasked with creating a query to retrieve all products whose names start with 'Laptop' and are priced below 1000. Additionally, the results should be sorted by price in ascending order. Which query syntax would you use?
- A
search=ProductName: 'Laptop*'&$filter=Price lt 1000&$orderby=Price asc
- B
search=ProductName eq 'Laptop*'&$filter=Price lt 1000&$orderby=Price asc
- C
search=ProductName: 'Laptop*'&filter=Price lt 1000&orderby=Price desc
- D
search=ProductName: 'Laptop'&$filter=Price lt 1000&$orderby=Price asc
Show answer and explanation
Correct answer: A
Explanation
To query an index in Azure Cognitive Search, you can use the $filter, $orderby, and search functionalities. Wildcards like '' allow flexible matching in the search expression. In this case, 'Laptop' is used to find all products whose names start with 'Laptop', '$filter=Price lt 1000' filters products with prices less than 1000, and '$orderby=Price asc' ensures the results are sorted by price in ascending order.
- A. Correct.
This is the correct syntax. 'Laptop*' uses a wildcard to match products starting with 'Laptop', '$filter=Price lt 1000' filters products priced below 1000, and '$orderby=Price asc' sorts the results in ascending order by price.
- B. Incorrect.
This is incorrect because 'ProductName eq' is used for exact matches and does not support wildcards like '*'.
- C. Incorrect.
This is incorrect because 'orderby=Price desc' sorts the results in descending order, not ascending as required.
- D. Incorrect.
This is incorrect because 'Laptop' without the wildcard '*' will only match exact product names and will not include products that start with 'Laptop'.