Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion plugins/out_es/es.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions tests/runtime/out_elasticsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,47 @@ void flb_test_write_operation_upsert()
flb_destroy(ctx);
}

void flb_test_null_index()
Copy link
Contributor

@mabrarov mabrarov May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test need to be added into TEST_LIST? Refer to https://github.com/mity/acutest/blob/master/README.md#basic-use.

{
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;
Expand Down
Loading