提问:布和纸怕什么?

es7.13.1 采集节点管道处理数据 可以取出库中的数据 和 新增数据比较吗?

匿名 | 发布于2021年09月24日 | 阅读数:1085

实现功能:新插入一条指定id的数据,如果库中这条数据存在,比较 时间字段的值,取最早的时间存储。
PUT _ingest/pipeline/add_data_pipeline
{
"description": "Adds create_time timestamp to documents",
"processors": [
{
"script": {
"source":
"""
if(!ctx.containsKey('time')){
ctx['
time']=params['time']
} else {
if (ctx['time'].compareTo(params['time']) >= 0){
ctx['time']=params['time']
}
}
"""
}
}
]
}
报错:
"caused_by": { "type": "null_pointer_exception", "reason": "Cannot read field \"value\" because \"anotherString\" is null" }
已邀请:

caster_QL

赞同来自: yiyu

加载数据时,使用 pipelin 和 script,针对的都是要入库的文档数据判断处理;
更新数据时,可以使用 script 进行 es 内数据判断处理更新逻辑,例:根据ES内某个字段值设置另一个字段值。
POST _scripts/s1
{
  "script": {
    "source": """
      if (ctx._source.speaker=='Hamlet') { 
        ctx._source.is_hamlet='true' 
      }else{
        ctx._source.is_hamlet='false'
      }
    """,
    "lang": "painless"
  }
}
POST hamlet/_update_by_query
{
  "script": {
    "id": "s1"
  },
  "query": {
    "match_all": {}
  }
}
你的需求是在数据入库时,要同时根据加载的数据和 ES 内部数据结合判断,感觉不太好搞,如果已有方案,求同步到这里。

要回复问题请先登录注册