2025년 5월 18일 일요일

엘라스틱 Runtime field - 12th

잘 동작하는 정규표현식.


url 필드 추출.
PUT sample/_mapping
{
    "runtime": {
        "url": {
            "type": "keyword",
            "script": """
                if (doc['message.keyword'].value =~ /\?/) {
                    def str=/[^"]+"\S+ ([^?]+)\?/.matcher(doc['message.keyword'].value);
                    if (str.find()) {
                        emit(str.group(1))
                    }
                } else {
                    def str=/[^"]+"\S+ (\S+)/.matcher(doc['message.keyword'].value);
                    if (str.find()) {
                        emit(str.group(1))
                    }
                }
            """
        }
    }
}

필드는 잘 만들어졌는데,


조회가 안 된다. painless 스크립트에 정규표현식 제한을 걸어놓은 모양. (v9부터 걸린 건가?)


제한을 풀기 위한 script.painless.regex.enabled 설정 추가.


댓글 없음:

댓글 쓰기

크리에이티브 커먼즈 라이선스