作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了以下函数并得到如下所示的响应:
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/
我是一名优秀的程序员,十分优秀!