如何在NEST,C#中按周编写日期直方图的等效查询
在使用NEST时,我需要将以下查询转换为c#如何在NEST,C#中按周编写日期直方图的等效查询,c#,elasticsearch,asp.net-core,kibana,nest,C#,elasticsearch,Asp.net Core,Kibana,Nest,在使用NEST时,我需要将以下查询转换为c# "aggs": { "number_of_weeks": { "date_histogram": { "field": "@timestamp", "interval": "week" } } } 在Kibana中,输出为 我编写了以下查询,但
"aggs": {
"number_of_weeks": {
"date_histogram": {
"field": "@timestamp",
"interval": "week"
}
}
}
在Kibana中,输出为
我编写了以下查询,但它给我零个bucket,而在Kibana中,它返回许多bucket中的结果
var query3 = EsClient.Search<doc>(q => q
.Index("SomeIndex")
.Size(0)
.Aggregations(agg => agg.DateHistogram("group_by_week", e => e.Field(p => p.timestamp) .Interval(DateInterval.Week)
)) ;
var resultquery3 = query3.Aggregations.DateHistogram("group_by_week");
var query3=EsClient.Search(q=>q
.Index(“SomeIndex”)
.尺寸(0)
.Aggregations(agg=>agg.DateHistogram(“按周分组”),e=>e.Field(p=>p.timestamp).Interval(DateInterval.week)
)) ;
var resultquery3=query3.Aggregations.DateHistogram(“按周分组”);
在vs studio中,输出为
问题可能是
e => e.Field(p => p.timestamp)
不会序列化到Elasticsearch中的“@timestamp”
字段。要使其工作,您需要
或者将其映射到ConnectionSettings
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
.DefaultMappingFor<Doc>(m => m
.PropertyName(e => e.timestamp, "@timestamp")
);
var client = new ElasticClient(settings);
您可以共享
doc
定义吗?您在聚合e.field(p=>p.timestamp)中使用的映射字段可能有问题
。可能您没有用属性标记timestamp
属性,并且NEST没有正确映射字段名。是的,这就是问题所在。它解决了例如,我做了第四个,它对我有效。谢谢
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
.DefaultMappingFor<Doc>(m => m
.PropertyName(e => e.timestamp, "@timestamp")
);
var client = new ElasticClient(settings);
.Field("@timestamp")