0
我有一個Elasticsearch數據庫和我有一個索引test
轉換Elasticsearch JSON查詢到C#NEST
這裏的模式:
PUT test
{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"channel" : {
"properties" : {
"id" : { "type" : "integer" },
"name" : { "type" : "string" }
}
},
"segment" : {
"properties" : {
"groupid" : { "type" : "text", "fielddata": true },
"instrName" : { "type" : "text", "fielddata": true },
"channelList" : { "type" : "object" }
}
}
}
}
我想這個查詢轉換成C#NEST代碼:
GET /test/segment/_search
{
"aggs": {
"agg": {
"terms": {
"field": "instrName"
},
"aggs": {
"agg2": {
"terms": {
"field": "groupid"
}
}
}
}
}
}
我懂得一個聚集查詢,但不能嵌套聚合
轉換10編輯
這裏目前的代碼,但我得到一個500錯誤從ES
var res = elastic.Search<SegmentRecord>(
s => s.Index(esIndex).Aggregations(a => a.Terms("instrName", x => x.Aggregations(w => w.Terms("groupid", sel => sel)))));
你能告訴我們你現有的C#代碼? – mjwills
看看嵌套的彙總用法示例:https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/nested-aggregation-usage.html –
@mjwills剛剛做到了。請看看,謝謝 –