2

我编写了以下函数并获得如下所示的响应:

  public async Task<GetMappingResponse> ShowMapping(string indexname)
        {
            var result =await _client.Indices.GetMappingAsync(new GetMappingRequest(indexname));
            return result;
        }

回复:

{
    "apiCall": {
        "auditTrail": [
            {
                "event": 5,
                "node": {
                    "clientNode": false,
                    ......
                    ......                  
                    "name": null,
                    "settings": {},
                    "uri": "http://localhost:9200/"
                },
                "path": "pure/_mapping",
                "ended": "2020-01-22T11:25:48.2324298Z",
                "started": "2020-01-22T11:25:47.836833Z",
                "exception": null
            }
        ],
        "debugInformation": "Successful (200) low level call on GET: /pure/_mapping\r\n# Audit trail of this API call:\r\n - [1] PingSuccess: Node: http://localhost:9200/ Took: 00:00:00.1716082\r\n - [2] HealthyResponse: Node: http://localhost:9200/ Took: 00:00:00.3955968\r\n# Request:\r\n<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>\r\n
         #Response:\r\n{\"pure\":{\"mappings\":{\"properties\":{\"ID\":{\"type\":\"integer\"},\"Name\":{\"type\":\"text\"},\"category\":{\"type\":\"nested\",\"properties\":{\"catid\":{\"type\":\"integer\"},\"catname\":{\"type\":\"text\"}}}}}}}\r\n",
        "deprecationWarnings": [],
         ..........
         ..........
        "uri": "http://localhost:9200/pure/_mapping",
        "connectionConfiguration": {}
    }
}

正如您所看到的调试信息字段确实有我需要的响应,任何人都可以帮助我如何获得像我们在 kibana 中获得的映射格式。

要求的回应:

{
    "pure": {
        "mappings": {
            "properties": {
                "ID": {
                    "type": "integer"
                },
                "Name": {
                    "type": "text"
                },
                "category": {
                    "type": "nested",
                    "properties": {
                        "catid": {
                            "type": "integer"
                        },
                        "catname": {
                            "type": "text"
                        }
                    }
                }
            }
        }
    }
}
4

1 回答 1

5

使用 NEST,JSON 响应被反序列化为可使用的 .NET 类型,在本例中为GetMappingResponse. 您可以遍历此类型的属性以检查映射。

如果您希望将 JSON 响应作为字符串获取,则可以使用低级客户端来执行此操作。低级客户端暴露在高级客户端(NEST)上

var client = new ElasticClient();
var indexName = "pure";
var response = client.LowLevel.Indices.GetMapping<StringResponse>(indexName);

// the JSON string response
var jsonMapping = response.Body;
于 2020-01-24T02:34:35.033 回答