我创建了一个脚本,用于记录应用于我的弹性文档的标签的历史记录。标签的名称是动态的,因此当我尝试将当前标签移动到历史字段时,对于尚不具有历史字段的标签会失败。
这是我的脚本,用于将当前标签复制到标签历史字段:
script:"ctx._source.tags[params.tagName.toString()].history.add(ctx._source.tags[params.tagName.toString()].current)"
Run Code Online (Sandbox Code Playgroud)
这些文件是这样的:
"tags": {
"relevant": {
"current": {
"tagDate": 1501848372292,
"taggedByUser": "dev",
"tagActive": true
},
"history": [
{
"tagDate": 1501841137822,
"taggedByUser": "admin",
"tagActive": true
},
{
"tagDate": 1501841334127,
"taggedByUser": "admin",
"tagActive": true
},
}}}}
Run Code Online (Sandbox Code Playgroud)
用户可以动态添加新标签,所以我想要做的是创建历史对象(如果它不存在),然后我可以填充它。
可用于elasticsearch脚本的文档非常少,所以我希望明智的人能够知道答案,因为我确信检查字段并创建它是elastic脚本语言的基本内容。
更新
因此,重新考虑该索引的结构后,我想要实现的目标如下:
tags:[
{hot:
{current:{tagDate:1231231233, taggedbyUser: user1, tagStatus: true},
history:[ {tagDate:123444433, taggedbyUser: user1, tagStatus: true},
{tagDate:1234412433, taggedbyUser: user1, tagStatus: true}
]
}
{interesting:
{current:{tagDate:1231231233, taggedbyUser: user1, tagStatus: true},
history:[ {tagDate:123444433, taggedbyUser: user1, tagStatus: true},
{tagDate:1234412433, taggedbyUser: user1, tagStatus: true}
]
}
] …Run Code Online (Sandbox Code Playgroud) 我正在使用notes.jar lotus notes api来提取电子邮件的日期和时间.当我将它们添加到集合中时,如果像这样添加它们:
Vector times = doc.getItemValueDateTimeArray("PostedDate");
for (int j=0; j<times.size(); j++) {
Object time = times.elementAt(j);
if (time.getClass().getName().endsWith("DateTime")) {
String Listadd = ((DateTime)time).getLocalTime();
NotesDates.add((DateTime)time);
Run Code Online (Sandbox Code Playgroud)
我收到错误:
lotus.domino.local.DateTime cannot be cast to java.lang.Comparable
Run Code Online (Sandbox Code Playgroud)
当我将值添加为String时代码运行,但我无法对集合进行排序.
如何对日期和时间的集合进行排序以找到最早和最新的?
如何按源数据中的字段对聚合的输出进行排序,而不是聚合输出的一部分?
在我的源数据中,我有一个日期字段,我希望按日期对聚合的输出进行排序。
那可能吗?我已经看过在汇总中使用“订单”,但是我认为它看不到该日期字段可用于排序吗?
我还尝试添加包括日期字段的子聚合,但是同样,我无法在该字段上对它进行排序。
我正在为ETL计算ETL中每个文档的哈希值。我的数据集包含很多重复项,因此我尝试使用哈希字段上的聚合来过滤出重复项,并且效果很好。我需要聚合的输出来保留日期排序顺序,以便可以按角度使用输出。
这些文件是这样的:
{_id: 123,
_source: {
"hash": "01010101010101"
"user": "1"
"dateTime" : "2001/2/20 09:12:21"
"action": "Login"
}
{_id: 124,
_source: {
"hash": "01010101010101"
"user": "1"
"dateTime" : "2001/2/20 09:12:21"
"action": "Login"
}
{_id: 132,
_source: {
"hash": "0202020202020"
"user": "1"
"dateTime" : "2001/2/20 09:20:43"
"action": "Logout"
}
{_id: 200,
_source: {
"hash": "0303030303030303"
"user": "2"
"dateTime" : "2001/2/22 09:32:14"
"action": "Login"
}
Run Code Online (Sandbox Code Playgroud)
因此,我想对哈希值使用聚合,以从集合中删除重复项,然后按日期顺序呈现响应。
我的查询:
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{ …Run Code Online (Sandbox Code Playgroud)