1

Using the high level client I'm able to send KV pairs (as a document) to elastic. I can query these using curl so I know they're in. What they lack is some equivalent to the "@timestamp" value that logstash seems to add. I haven't found what the syntax for this field is (or what the appropriate field would be).

Epoch? TZ?

1 Answer 1

3

FWIW - if you want these values to be available in kibana just use SimpleDateFormat like so:

    Date date = new Date(System.currentTimeMillis());

    // Conversion
    SimpleDateFormat sdf;
    sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    String stamp = sdf.format(date);

Then add this to your HashMap as '@timestamp':

    // write to elastic
    RestHighLevelClient client = getClient();
    Map<String, Object> mapObject = new HashMap();
    mapObject.put("type", "consumer_test");
    mapObject.put("test.group", group);
    mapObject.put("test.topic", topic);
    mapObject.put("test.sum", sumLag);
    mapObject.put("@timestamp", stamp);

    IndexRequest indexRequest = new IndexRequest(index).source(mapObject);

    try {
        IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
        client.close();
    } catch(Exception e) {
        LOGGER.error("exception from indexing request", e);
        return false;
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.