Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] ElasticSearchException Metric Scripted class_cast_exception 이슈 #7

Open
gkdbssla97 opened this issue May 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@gkdbssla97
Copy link
Contributor

ErrorLog

ErrorCause: {"phase":"query","failed_shards":[{"shard":0,"index":"player_performance","node":"vEp17EizQHuI39IqXskk5w","reason":{"type":"script_exception","reason":"runtime error","script_stack":["wardsScore = (wardsPlaced * 0.5) + (doc['detectorWardsPlaced'] * 0.5);\n double ","^---- HERE"],"script":"String lane = doc['lane'].value; ...","lang":"painless","position":{"offset":545,"start":506,"end":585},"caused_by":{"type":"class_cast_exception","reason":"Cannot apply [*] operation to types [org.elasticsearch.index.fielddata.ScriptDocValues.Longs] and [java.lang.Double]."}}}],"...","type":"script_exception","reason":"runtime error"}]}

에러 원인

Painless 스크립트 실행 중 발생한 script_exception으로, 스크립트에서 런타임 에러가 발생. class_cast_exception이 발생했으며, 데이터 타입 간에 적절하지 않은 연산 시도가 원인

에러의 핵심 내용

Cannot apply [*] operation to types [org.elasticsearch.index.fielddata.ScriptDocValues.Longs] and [java.lang.Double].
이 메시지는 곱셈 연산(*)을 ScriptDocValues.Longs 타입과 java.lang.Double 타입에 적용하려고 시도했으나, 이 두 타입 간에는 곱셈 연산을 직접 수행할 수 없음

문제가 발생한 스크립트 부분

wardsScore = (wardsPlaced * 0.5) + (doc['detectorWardsPlaced'] * 0.5);
여기서 wardsPlaced가 ScriptDocValues.Longs 타입으로 직접적으로 부동소수점 숫자인 0.5와의 곱셈 연산을 시도했기 때문에 타입 불일치로 인한 에러가 발생한 것으로 보임

에러 해결

wardsScore = ((double) wardsPlaced * 0.5) + ((double) doc['detectorWardsPlaced'].value * 0.5);
wardsPlaced와 doc['detectorWardsPlaced'].value를 double 타입으로 명시적으로 캐스팅하여 두 값 모두 부동소수점 연산이 가능한 타입으로 변환한 후 곱셈 연산을 수행
타입을 명확히 지정함으로써 class_cast_exception 에러 해결

@gkdbssla97
Copy link
Contributor Author

gkdbssla97 commented May 24, 2024

catch (ElasticsearchException e){
    log.info(e.response().error().toString());
    throw e;
}

디버깅 안찍으니까 ElasticSearch 에러로만 로그 출력

@gkdbssla97 gkdbssla97 added the bug Something isn't working label May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant