Hi,
I want to create an index template roughly like so:
$this->getElasticsearchClient()
->indices()
->putTemplate([
'name' => 'my_template',
'body' => [
'template' => 'index-matcher-*',
'aliases' => [
// register an alias for each new index so that we can
// perform index migrations without downtime
// only use the read- prefixed indices to query for data
'read-{index}' => [],
],
],
])
;
However, I get a 400 BadRequest with the error ElasticsearchIllegalArgumentException[No alias specified]
If I use 'read-{index}' => ['a' => 'b'], instead, it works.
Are options to the index alias mandatory? Specifying dummy options just to have an associative array seems to circumvent that?
Ah, this is an unfortunate quirk of PHP and json_encode. You can specify an empty JSON object ({}) by using an explicit empty PHP object. Try this:
$this->getElasticsearchClient()
->indices()
->putTemplate([
'name' => 'my_template',
'body' => [
'template' => 'index-matcher-*',
'aliases' => [
// register an alias for each new index so that we can
// perform index migrations without downtime
// only use the read- prefixed indices to query for data
'read-{index}' => new \stdClass(),
],
],
])
;
If that doesn't work, I'll break out the debugger and see what's going on. :)
Hi, thanks! I figured something like this might be going on. stdClass works.
Most helpful comment
Ah, this is an unfortunate quirk of PHP and
json_encode. You can specify an empty JSON object ({}) by using an explicit empty PHP object. Try this:If that doesn't work, I'll break out the debugger and see what's going on. :)