gpt4 book ai didi

c# - Elasticsearch无法从BucketScript中读取ScriptedMetric?

转载 作者:行者123 更新时间:2023-12-03 00:02:37 28 4
gpt4 key购买 nike

我应该工作,因为ScriptedMetric是一个指标,它确实返回一个数字值,但是我无法使其正常工作。

我在C#中使用NEST(通过NuGet使用5.5.0,我将Elasticsearch 6.0.0定位为目标)使其正常工作,但是我也尝试在Kibana中构建相同的查询以排除NEST问题。在基巴纳语中,我得到了完全相同的错误。

错误:

buckets_path must reference either a number value or a single value numeric metric aggregation, got: org.elasticsearch.search.aggregations.metrics.scripted.InternalScriptedMetric



我的代码:
ISearchResponse<LogItem> aggregationResponse = await client.SearchAsync<LogItem>(s => s
.Size(0)
.Type("errordoc")
.Query(...)
.Aggregations(a => a
.Terms("Hash", st => st
.Field(o => o.messageHash.Suffix("keyword")).OrderDescending("Avg-Score")
.Aggregations(aa => aa
.Terms("Friendly", ff => ff
.Field(oo => oo.friendly.Suffix("keyword"))
)
.Max("Max-DateTime", ff => ff
.Field(oo => oo.dateTimeStamp)
)
.Average("Avg-Score", sc => sc
.Script("_score")
)
.ScriptedMetric("Urgency-Level", sm => sm
.InitScript(i => i.Inline("params._agg.data = []").Lang("painless"))
.MapScript(i => i.Inline("params._agg.data.add(doc.urgency.value)").Lang("painless"))
.CombineScript(i => i.Inline("int urgency = 0; for (u in params._agg.data) { urgency += u } return urgency").Lang("painless"))
.ReduceScript(i =>i.Inline("int urgency = 0; for (a in params._aggs) { urgency += a } return urgency").Lang("painless"))
)
.BucketScript("finalScore", scb => scb
.BucketsPath(bp => bp
.Add("maxDateTime", "Max-DateTime")
.Add("avgScore", "Avg-Score")
.Add("urgencyLevel", "Urgency-Level")
)
.Script(i => i.Inline("params.avgScore").Lang("painless"))
)
)
)
)
);

ScriptedMetric聚合返回的数据集为11。

难道我做错了什么?还是不可能?如果不可能的话,有什么替代方法?

另外,我知道这个ScriptedMetric几乎可以完成Sum的工作,但这当然会改变...

索引映射:
PUT /live
{
"mappings": {
"errordoc": {
"properties": {
"urgency": {
"type": "integer"
},
"dateTimeStamp": {
"type": "date",
"format": "MM/dd/yyyy hh:mm:ss a"
} }
}
}
}

测试数据:
POST /live/errordoc
{ "messageID": "M111111", "messageHash": "1463454562\/-1210136287\/-1885530817\/-275007043\/-57589585", "friendly": "0", "urgency": "1", "organisation": "Organisation Name", "Environment": "ENV02", "Task": "TASK01", "Action": "A12", "dateTimeStamp": "11\/29\/2017 10:24:21 AM", "machineName": "DESKTOP-SMOM9R9", "parameters": "{ " }

复制此文档几次,也许更改urgency / dateTimeStamp,只要哈希保持不变,它就应该重现我的环境...

最佳答案

我创建了2个GitHub问题后,Elasticsearch论坛上的某人回答了...
我确实尝试了所有方法,包括此解决方案,但是在尝试过程中我一定做错了其他任何事情……

解决方案

更改:

.Add("urgencyLevel", "Urgency-Level")

至:
.Add("urgencyLevel", "Urgency-Level.value")

关于c# - Elasticsearch无法从BucketScript中读取ScriptedMetric?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47595134/

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