As everyone can see in their GitHub page there's an inner type tag for the property tag which is supposed to tell Elasticsearch if the value of that property should be written as a string, number... in the resulting JSON (at least that's what I understand):
type (optional, default String): type of the field on the resulting JSON message. Possible values are: String, int, float and boolean.
But I can't make it work.
This is the snippet of my logback.xml file:
<appender name="ELASTIC" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
...
<property>
<name>elapsed time (ms)</name>
<value>%X{elapsedTime}</value>
<type>int</type>
</property>
...
</appender>
and I'm configuring logback using JoranConfigurator:
String logConfigurationPath = "logback.xml";
if (logConfigurationPath != null) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
JoranConfigurator config = new JoranConfigurator();
config.setContext(context);
context.reset();
config.doConfigure(logConfigurationPath);
} catch (JoranException je) {
}
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
Logback configures OK, but when it tries to process that type tag I get an error:
testingdocker | 09:46:13,134 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@68:23 - no applicable action for [type], current ElementPath is [[configuration][appender][properties][property][type]]
And Elastic set that tag in the resulting JSON as a String, as I can check in Kibana.
How can I use that tag properly so I get number types in Kibana from Logback?
It seems to be a bug in the appender.
If you see Property.java, you will see:
public void setType(String type) {
try {
this.type = Enum.valueOf(Type.class, type.toUpperCase());
} catch (IllegalArgumentException e) {
this.type = Type.STRING;
}
}
So, if you set something that is not in Enum, it will use String. This is fine. So we can see about Type:
public enum Type {
STRING, INT, FLOAT, BOOLEAN
}
And I think here you are problem! ElasticSearch do not accept the type "int", but "integer".
More information about data types: