Azure Search - Part 9 ( 使用 REST API 查詢 Azure Search Index)在完成前置作業(1. 申請 Azure Search  2. 建立 Azure Search Index 2. 建立 index 資料)後,終於可以開始實際使用,查詢方式目前有三個:1. Azure Portal 2. .NET SDK 3.REST API,前面已經看過 .NET SDK 如何使用,接著就來試試 REST API.
Azure Search Service Key
| key Type | 備註 | 用途說明 | 
|---|---|---|
| admin keys(系統管理金鑰) | 主要/次要 | 管理服務、建立/刪除 Index、索引子、資料來源;主要/次要用途相同 | 
| query keys(查詢金鑰) | - | 提供 client 端用來讀取 index 與 document | 
Azure PortalAzure Search金鑰主要管理金鑰 或是 次要管理金鑰查詢金鑰查詢金鑰,符合 最低權限準則
api-key
api-key: [query key]
Accept
Accept: application/json
Content-Type
Content-Type: application/json
POST https://[service name].search.windows.net/indexes/[index name]/docs/search?api-version=[api-version]
Content-Type: application/json
Accept: application/json
api-key: [query key]
api-key
api-key: [query key]
Accept
Accept: application/json
GET https://[service name].search.windows.net/indexes/[index name]/docs?[query parameters]
Accept: application/json
api-key: [query key]
GET 與 POST 的 URL 格式有些許不同Search Documents (Azure Search Service REST API)
Searchable 欄位內容 search "budget" 取得 "hotelName" 欄位內容GET
https://[service name].search.windows.net/indexes/hotels/docs?search=budget&$select=hotelName&api-version=2015-02-28
POST
https://[service name].search.windows.net/indexes/hotels/docs/search?api-version=2015-02-28
{
    "search": "budget",
    "select": "hotelName"
}
filter "baseRate" 欄位 小於 150 ,取得 "hotelId", "description" 欄位內容,不 search(* 表不指定條件 search)GET
https://[service name].search.windows.net/indexes/hotels/docs?search=*&$filter=baseRate lt 150&$select=hotelId,description&api-version=2015-02-28
POST
https://[service name].search.windows.net/indexes/hotels/docs/search?api-version=2015-02-28
{
    "search": "*",
    "filter": "baseRate lt 150",
    "select": "hotelId,description"
}
filter 以 "lastRenovationDate" 欄位遞減排序,取回 "hotelName", "lastRenovationDate" 欄位內容,只取前兩筆,不 search(* 表不指定條件 search)GET
https://[service name].search.windows.net/indexes/hotels/docs?search=*&$top=2&$orderby=lastRenovationDate desc&$select=hotelName,lastRenovationDate&api-version=2015-02-28
POST
https://[service name].search.windows.net/indexes/hotels/docs/search?api-version=2015-02-28
{
    "search": "*",
    "orderby": "lastRenovationDate desc",
    "select": "hotelName,lastRenovationDate",
    "top": 2
}
filter,只針對 Searchable 欄位內容 search "motel"GET
https://[service name].search.windows.net/indexes/hotels/docs?&api-version=2015-02-28&search=motel
POST
https://[service name].search.windows.net/indexes/hotels/docs/search?api-version=2015-02-28
{
    "search": "motel"
}
Azure Search 的內容滿多的,幾天下來還是只看了基本觀念跟使用方式,實際應用上就看大家怎麼發揮創意了,另外管理面或是系統面的功能,依實際用途、用量會有不同用法,就不一一介紹,接下來內容會是使用 indexer 與其他 Azure 資源的整合。