diff --git a/plugins/out_es/es.c b/plugins/out_es/es.c index c896b1ed258..4e653e7e349 100644 --- a/plugins/out_es/es.c +++ b/plugins/out_es/es.c @@ -627,6 +627,11 @@ static int cb_es_init(struct flb_output_instance *ins, return -1; } + if (ctx->index == NULL && ctx->logstash_format == FLB_FALSE && ctx->generate_id == FLB_FALSE) { + flb_plg_error(ins, "cannot initialize plugin, index is not set and logstash_format and generate_id are both off"); + return -1; + } + flb_plg_debug(ctx->ins, "host=%s port=%i uri=%s index=%s type=%s", ins->host.name, ins->host.port, ctx->uri, ctx->index, ctx->type); @@ -937,7 +942,7 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk, /* * If trace_error is set, trace the actual * response from Elasticsearch explaining the problem. - * Trace_Output can be used to see the request. + * Trace_Output can be used to see the request. */ if (pack_size < 4000) { flb_plg_debug(ctx->ins, "error caused by: Input\n%.*s\n", diff --git a/tests/runtime/out_elasticsearch.c b/tests/runtime/out_elasticsearch.c index eac72cbf321..3b67d56d432 100644 --- a/tests/runtime/out_elasticsearch.c +++ b/tests/runtime/out_elasticsearch.c @@ -347,6 +347,47 @@ void flb_test_write_operation_upsert() flb_destroy(ctx); } +void flb_test_null_index() +{ + int ret; + int size = sizeof(JSON_ES) - 1; + flb_ctx_t *ctx; + int in_ffd; + int out_ffd; + /* Create context, flush every second (some checks omitted here) */ + ctx = flb_create(); + flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + + /* Lib input mode */ + in_ffd = flb_input(ctx, (char *) "lib", NULL); + flb_input_set(ctx, in_ffd, "tag", "test", NULL); + + /* Elasticsearch output */ + out_ffd = flb_output(ctx, (char *) "es", NULL); + flb_output_set(ctx, out_ffd, + "match", "test", + NULL); + + /* Override defaults of index and type */ + flb_output_set(ctx, out_ffd, + "index", "", + "type", "type_test", + NULL); + + /* Enable test mode */ + ret = flb_output_set_test(ctx, out_ffd, "formatter", + cb_check_index_type, + NULL, NULL); + + /* Start */ + ret = flb_start(ctx); + TEST_CHECK(ret == -1); + + sleep(2); + flb_stop(ctx); + flb_destroy(ctx); +} + void flb_test_index_type() { int ret;