如何使用 Azure 认知搜索进行分面搜索?

How to do faceted search with Azure cognitive search?

我正在尝试在 Azure 认知搜索中进行分面搜索。我正在使用 postman(和 curl)进行测试。

获得了一个可显示的字段 state_name。在 https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents 之后,如果我将 POST 请求负载发送为:

{
    "facets": "state_name"
}

它returns这个错误:

{
    "error": {
        "code": "",
        "message": "The request is invalid. Details: parameters : When trying to read a null collection parameter value in JSON Light, a node of type 'PrimitiveValue' with the value 'state_name' was read from the JSON reader; however, a primitive 'null' value was expected.\r\n"
    }
}

进行分面搜索的正确方法是什么?


更新:

payload中的

facets应该是一个数组:

{
    "facets": ["state_name"]
}

如图https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents#bkmk_examples

您需要将构面字段指定为 url 的一部分:

GET /indexes/hotels/docs?search=*&facet=state_name&api-version=2019-05-06

更多信息:https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents#bkmk_examples