ElasticsearchBundle icon indicating copy to clipboard operation
ElasticsearchBundle copied to clipboard

CLI command behaviour unpredictable when run without --index option and multiple indices

Open macghriogair opened this issue 4 years ago • 0 comments

ONGR cli commands act on unpredictable indices when executed without --index option

  • Bundle Versions: 6.7.2 and 7.x
  • Elasticsearch Version: 6.7 and 7.6
  • PHP Version 7.4

Expected behaviour:

  • --index option should be either required OR commands should be executed on all indices (where possible)

Actual behaviour:

  • an unpredictable index is used when commands are executed without --index

Steps to reproduce:

Having mutliple indices + document classes:

config.yml


ongr_elasticsearch:
    # ...
    indexes:
            AppBundle\Search\Document\AcmeApple:
                alias: acme_apples
                hosts:
                    - '%elasticsearch.host%'
            AppBundle\Search\Document\AcmeBanana:
                alias: acme_banana
                hosts:
                    - '%elasticsearch.host%'
            AppBundle\Search\Document\AcmePotatoe:
                alias: acme_potatoe
                hosts:
                    - '%elasticsearch.host%'

Any of the following commands will be executed on just one index

  • ongr:es:cache:clear
  • ongr:es:index:create
  • ongr:es:index:drop
  • ongr:es:index:export
  • ongr:es:index:import

Console output:


# Drop indices
www-data@41995e1973b5:/php$ bin/console ongr:es:index:drop -f

 The index `acme_banana` was successfully dropped.
# Create indices
www-data@41995e1973b5:/php$ bin/console ongr:es:index:create

 Created `acme_banana` index.

# Clear cache
www-data@41995e1973b5:/php$ bin/console ongr:es:cache:clear

 [OK] Elasticsearch `acme_banana` index cache has been cleared.

# Export
 www-data@41995e1973b5:/php$ bin/console ongr:es:index:export foo.json
# foo contains data of index `acme_banana`
# and so on...

Our workaround is a bash script to loop over all indices for tasks such as mapping updates/cache clear/reindex etc.

macghriogair avatar Sep 24 '20 11:09 macghriogair