2017-04-17 1 views
0

elasticsearch watcher 출력에서 ​​payload.hits.hits을 json으로 변환하고 싶습니다. 내가 찾은 해결책은 스크립트 변환 그루비 같이elasticsearch 출력을 그루비로 json으로 변환하십시오.

PUT _watcher/watch/error_alert 
{ 
"trigger": { 
    "schedule": { 
    "interval": "1m" 
} 
}, 
"input": { 
"search": { 
    "request": { 
    "body": { 
     "query": { 
     "bool": { 
      "must": [ 
      { 
       "query_string": { 
       "default_field": "message", 
       "query": "ERROR" 
       } 
      }, 
      { 
       "range": { 
       "@timestamp": { 
        "gte": "now-1m", 
        "lte": "now" 
       } 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 
}, 
"condition": { 
    "compare": { 
    "ctx.payload.hits.total": { 
     "gt": 0 
    } 
} 
}, 
"transform" : { 
    "script" : "return [ body: groovy.json.JsonOutput.toJson(ctx.payload.hits.hits)]" 
}, 
"actions": { 
"some_webhook": { 
    "webhook": { 
    "method": "POST", 
    "host": "*.*.*.*", 
    "port": 4000, 
    "path": "/sms", 
    "headers": { 
     "Content-Type": "application/json" 
    }, 
    "body": "message: {{ctx.payload.body}}" 
    } 
} 
} 
} 

이 요청이 예외가 반환 내가 다른 솔루션 많은 시도

"type": "general_script_exception", 
    "reason": "failed to compile script [ScriptException[compile error]; nested: IllegalArgumentException[Variable [body] is not defined.];]" 

을하지만 저를 제외하고 대부분의 사람들을 위해 작동하는 것 같다!

내가 사용

  • Elasticsearch 5.3.0
  • 키바 5.0.2

에게 누군가가 제발 도와 드릴까요!

답변

0

json의 구문 문제와 유사합니다.

"return [ body: groovy.json.JsonOutput.toJson(ctx.payload.hits.hits)]" 

는 반환

"return { 'body': JsonOutput.toJson(ctx.payload.hits.hits)}" 
+0

보십시오 : **는 IllegalArgumentException ** –

+0

당신은 끝내 활성화해야 [변수 [멋] 정의되지 않았습니다.]. elasticsearch.yml 파일에서 다음을 설정하십시오 script.engine.groovy.inline.search : on – Ervin

+0

Groovy IS가 활성화 된 것 같습니다. 두 번째로 생각했지만 json이 groovy.json.JsonOutput을 호출하지 못하도록 할 수 있는지 확신하지 못합니다. JsonOutput을 호출 해봤습니까? – Ervin

관련 문제