试试搜索一下吧

can not write type [class java.util.HashSet]

Elasticsearch | 作者 lengchanguo | 发布于2019年04月11日 | 阅读数:1948

我在社区找到一个利用scripted_metric做ES交集的DSL,放到自己的es 5.5.1版本执行后报错:can not write type [class java.util.HashSet],具体DSL如下:
{
"size": 0,
"query": {
"bool": {
"should": [
{
"range": {
"pt": {
"gte": "1554566400",
"lte": "1554566400"
}
}
},
{
"range": {
"pt": {
"gte": "1554480000",
"lte": "1554480000"
}
}
}
]
}
},
"aggs": {
"intersect": {
"scripted_metric": {
"init_script": "params._agg.a=new HashSet();params._agg.b=new HashSet()",
"map_script": "if(doc['pt'].value >= 1554566400&&doc['pt'].value <= 1554566400){params._agg['a'].add(doc['pn'].value);}if(doc['pt'].value >= 1554480000&&doc['pt'].value <= 1554480000){params._agg['b'].add(doc['pn'].value)}",
"reduce_script": "def a=new HashSet(),b=new HashSet();params._aggs.forEach(item->{a.addAll(item.a);b.addAll(item.b);});a.retainAll(b);return a"
}
}
}
}
请问有什么解决方法吗
已邀请:

lengchanguo - 得一爸

赞同来自:

https://www.elastic.co/guide/e ... types
  
Whilst any valid script object can be used within a single script, the scripts must return or store in the _agg object only the following types:

primitive types
String
Map (containing only keys and values of the types listed here)
Array (containing elements of only the types listed here)
 
params._agg.a=new HashSet();params._agg.b= new HashSet();改为params._agg.a=[];params._agg.b=[]

要回复问题请先登录注册