FOSElasticaBundle
FOSElasticaBundle copied to clipboard
index is created instead of alias on entity creation
we have an index called "leads", part of config of this index is:
indexes: leads: use_alias: true index_name: leads
when running pupolate command it works as expected: alias and timestamped index are created. However, if there are some entities created before the creation of the alias (which triggers syncronization to elastic search), for some reason, an index called "leads" is appearing (not alias).
are we doing anything wrongly or it is indeed a bug in the bundle?
I have the same problem.
When a single entity is modified, the app will look for an index called leads
. If it can't find one, or it can't find an index with the alias of leads
, it will create a new index.
$ curl http://localhost:9200/_aliases | json_pp
{
"leads" : {
"aliases" : {
}
}
}
There's also another edge case: if your application has a working index + alias configuration, and you kick off a long running populate command, then elasticsearch will look like this...
$ curl http://localhost:9200/_aliases | json_pp
{
"leads_2019-09-25-100000" : { # current live search index
"aliases" : {
"leads" : {}
}
},
"leads_2019-09-25-102000" : { # new populating search index
"aliases" : {
}
}
}
Any publish requests received during this time will be sent to the current live index, leads_2019-09-25-100000
.
After the populate command has finished and the aliases are swapped, those newly published changes will be lost as index leads_2019-09-25-100000
is dropped.
I have a similar problem
but my workaround is to run the fos:elastica:create
command first to make sure the index/aliased index was created before the entity was saved.
Also beware, please use ^6.2.0
if you are using an alias in your setting, coz it used an incorrect alias name <6.2.0
, see change log here https://github.com/timching/FOSElasticaBundle/blob/master/CHANGELOG-6.0.md#620-2022-08-31
I believe that this happens because the fos_elastica's listener config will be triggered once we save the entity.
UPDATE
just took a quick look at the source code, the index created here https://github.com/timching/FOSElasticaBundle/blob/f44abba6cf6a902ddcbbaac5acc2bdac7d8b318d/src/Persister/ObjectPersister.php#L132
since both functions are just setting the indexName to the doc (and that object dunno alias related info, coz it's an elastic package), that's why this weird behavior happened https://github.com/ruflin/Elastica/blob/0f6b04b5ebe6df51015fb54b4c455bd7af5b093f/src/Index.php#L278
https://github.com/ruflin/Elastica/blob/0f6b04b5ebe6df51015fb54b4c455bd7af5b093f/src/Index.php#L243C28-L243C43 https://github.com/ruflin/Elastica/blob/0f6b04b5ebe6df51015fb54b4c455bd7af5b093f/src/Index.php#L761
since I'm not familiar with both elastic & elastic bundle packages atm, I'm not sure how should I fix/tweak that correctly, so I will use the above workaround to make sure the aliased index exists before any entity created