Question

I built a cron job in Linux to run the following command every 5 minuets to update my elasticsearch index

php app/console fos:elastica:populate --no-reset --no-debug

And I have a nested object mapping for documents attachments as below:

...
types:
   documents:
      mappings:
         Title: ~
         Description: ~
         Attachments:
            type: "object"
               properties:
                  File_Name:
                  content:
                     type: attachment 
      persistence:
         driver: orm
         model: Acme\AcmeBundle\Entity\Documents
         provider: ~
         listener: ~
         finder: ~

It works properly to index my documents in DB and has no issue, except for the attachments. It does not index the attachments when the cron job runs, but if I run the populate command manually it will index my attachments. It's really weird and mixed me up.

One more thing which may help to find a solution: I built same schedule task in windows machine to run the command and it works without any issue

Appreciate it if you could help

Was it helpful?

Solution

Finally I could fix this issue. In fact it was not FOSelasticabundle issue, the problem was with the cronjob.
I was running the crontab as below:

#m h  dom mon dow   command
*/2 * * * *  /var/www/Symfony/populateElastica.sh

I found it needs to be redirected the path which the script needs to be run then works perfectly

#m h  dom mon dow   command
*/2 * * * *  cd /var/www/Symfony && /var/www/Symfony/buildAcmeIndex.sh

You need to define the shell script for buildAcmeIndex.sh as:

#! /bin/sh
echo -------------- Auto Index Started ----------------
/usr/bin/php /var/www/Symfony/app/console fos:elastica:populate --env=prod --no-reset
echo --------------- Auto Index done! -----------------

Just keep in mind to set the path of php as the proper path in Linux server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top