创建索引Azure搜索API问题

时间:2014-12-17 17:46:20

标签: azure azure-search

当我用zson格式的索引模式在azure上创建搜索索引时,我遇到了问题。我检查了json格式,一切都很好。但是在对azure搜索API的发布请求时,它会响应错误。

{"error":{"code":"","message":"The request is invalid.","innererror":{"message":"index : An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected.\r\n","type":"","stacktrace":""}}}

这是我的创建索引代码:

Dim client = New RestClient("https://xxxx.search.windows.net/indexes?api-version=2014-07-31-Preview")
        Dim request = New RestRequest(Method.POST)
        request.AddHeader("api-key", "asdasdsaD6AxxxxD7B572F17DBAC1")
        request.AddJsonBody(File.ReadAllText(Server.MapPath("~/IndexSchema.json")))
        Dim response = client.Execute(request)

此处找到IndexSchema.json文件内容

{
    "name": "musicstoreindex",
    "fields": [
        { "name": "key", "type": "Edm.String", "key": true },
        { "name": "albumTitle", "type": "Edm.String", "suggestions": true },
        { "name": "albumUrl", "type": "Edm.String", "filterable": false },
        { "name": "genre", "type": "Edm.String" },
        { "name": "genreDescription", "type": "Edm.String", "filterable": false },
        { "name": "artistName", "type": "Edm.String", "suggestions": true },
        { "name": "orderableOnline", "type": "Edm.Boolean" },
        { "name": "rating", "type": "Edm.Int32" },
        { "name": "tags", "type": "Collection(Edm.String)" },
        { "name": "price", "type": "Edm.Double", "filterable": false },
        { "name": "margin", "type": "Edm.Int32", "retrievable": false },
        { "name": "inventory", "type": "Edm.Int32" },
        { "name": "lastUpdated", "type": "Edm.DateTimeOffset" }
    ],
    "scoringProfiles": [
        {
            "name": "boostGenre",
            "text": {
                "weights": {
                    "albumTitle": 5,
                    "genre": 50,
                    "artistName": 5
                }
            }
        },
        {
            "name": "newAndHighlyRated",
            "functions": [
                {
                    "type": "freshness",
                    "fieldName": "lastUpdated",
                    "boost": 10,
                    "interpolation": "quadratic",
                    "freshness": {
                        "boostingDuration": "P365D"
                    }
                },
                {
                    "type": "magnitude",
                    "fieldName": "rating",
                    "boost": 10,
                    "interpolation": "linear",
                    "magnitude": {
                        "boostingRangeStart": 1,
                        "boostingRangeEnd": 5,
                        "constantBoostBeyondRange": false
                    }
                }
            ]
        },
        {
            "name": "boostMargin",
            "functions": [

                {
                    "type": "magnitude",
                    "fieldName": "margin",
                    "boost": 50,
                    "interpolation": "linear",
                    "magnitude": {
                        "boostingRangeStart": 50,
                        "boostingRangeEnd": 100,
                        "constantBoostBeyondRange": false
                    }
                }
            ]
        }
    ]
}

<德尔> https://www.dropbox.com/s/51ruzwg4hv0pnxa/schema.json?dl=0

0 个答案:

没有答案