gpt4 book ai didi

nest - 如何在 elasticsearch nest 中获取索引的映射?

转载 作者:行者123 更新时间:2023-12-02 19:42:42 26 4
gpt4 key购买 nike

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

  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": {}
}
}

如您所见,debuginformation 字段确实有我需要的响应,任何人都可以帮助我如何获得我们在 kibana 中获得的那种映射格式。

必填项:

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

最佳答案

使用 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;

关于nest - 如何在 elasticsearch nest 中获取索引的映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59858902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com