substringAfter() function
출처: 문서
본문
substringAfter() 함수
substringAfter() 함수는 문자열에서 지정된 구분자가 처음 나타나는 위치 뒤의 부분을 추출하는 데 사용돼요. 이 함수는 두 개의 인자를 받아요:
-
첫 번째 인자는 리터럴 문자열이거나 소스 문자열을 나타내는 JSON pointer예요.
-
두 번째 인자는 첫 번째 인자 안에서 검색할 구분자 문자열이에요.
구분자를 찾으면 함수는 구분자가 처음 나타나는 위치 뒤의 문자열 부분을 반환해요. 구분자를 찾지 못하면 원본 문자열을 반환해요. 소스가 null로 평가되면 함수는 null을 반환해요. 구분자가 null이거나 비어 있으면 원본 문자열을 반환해요.
예를 들어 header라는 필드에서 = 문자가 처음 나타나는 위치 뒤의 값을 추출하려면 다음과 같이 substringAfter() 함수를 사용해요:
'substringAfter(/header, "=")'
{% include copy.html %}
/header에 Content-Type=application/json이 들어 있다면 함수는 application/json을 반환해요.
또는 첫 번째 인자로 리터럴 문자열을 사용할 수도 있어요:
'substringAfter("hello-world-foo", "-")'
{% include copy.html %}
함수는 - 문자가 처음 나타나는 위치 뒤의 문자열 부분을 추출하기 때문에 world-foo를 반환해요.
substringAfter() 함수는 대소문자를 구분하는 검색을 수행해요.
{: .note}
예제
다음 파이프라인은 substringAfter() 함수를 사용해 이메일 주소 필드에서 도메인 이름을 추출해요. 그리고 추출한 도메인 이름을 domain이라는 새 필드로 추가해요:
substring-after-demo:
source:
http:
ssl: false
processor:
- add_entries:
entries:
- key: domain
value_expression: 'substringAfter(/email, "@")'
sink:
- opensearch:
hosts: ["https://opensearch:9200"]
insecure: true
username: admin
password: admin_password
index_type: custom
index: demo-index-%{yyyy.MM.dd}
{% include copy.html %}
다음 명령어로 파이프라인을 테스트할 수 있어요:
curl -sS -X POST "http://localhost:2021/log/ingest" \
-H "Content-Type: application/json" \
-d '[
{"email":"[email protected]"},
{"email":"[email protected]"}
]'
{% include copy.html %}
OpenSearch에 저장된 문서에는 다음 정보가 들어 있어요:
{
...
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "demo-index-2026.03.13",
"_id": "abc123",
"_score": 1,
"_source": {
"email": "[email protected]",
"domain": "example.com"
}
},
{
"_index": "demo-index-2026.03.13",
"_id": "def456",
"_score": 1,
"_source": {
"email": "[email protected]",
"domain": "opensearch.org"
}
}
]
}
}