org.elasticsearch.grok.GrokCaptureConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-grok Show documentation
Show all versions of elasticsearch-grok Show documentation
Elasticsearch subproject :libs:elasticsearch-grok
The newest version!
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.grok;
import org.joni.NameEntry;
import java.nio.charset.StandardCharsets;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;
import java.util.function.Function;
import java.util.function.IntConsumer;
import java.util.function.LongConsumer;
/**
* Configuration for a value that {@link Grok} can capture.
*/
public final class GrokCaptureConfig {
private final String name;
private final GrokCaptureType type;
private final int[] backRefs;
GrokCaptureConfig(NameEntry nameEntry) {
String groupName = new String(nameEntry.name, nameEntry.nameP, nameEntry.nameEnd - nameEntry.nameP, StandardCharsets.UTF_8);
String[] parts = groupName.split(":");
name = parts.length >= 2 ? parts[1] : parts[0];
type = parts.length == 3 ? GrokCaptureType.fromString(parts[2]) : GrokCaptureType.STRING;
this.backRefs = nameEntry.getBackRefs();
}
/**
* The name defined for the field in the pattern.
*/
public String name() {
return name;
}
/**
* The type defined for the field in the pattern.
*/
public GrokCaptureType type() {
return type;
}
/**
* Build a {@linkplain GrokCaptureExtracter} that will call {@code emit} when
* it extracts text, boxed if the "native" representation is primitive type.
* Extracters returned from this method are stateless and can be reused.
*/
public GrokCaptureExtracter objectExtracter(Consumer