<p>As of 3.1.2 you can now index assets via the cli tool:</p>

<pre><code>./craft index-assets/all 
</code></pre>

<p>OR</p>

<pre><code>./craft index-assets/one {handle}
</code></pre>

CC BY-SA 4.0
2019-01-30T00:42:29.833Z
2019-01-30T00:42:29.833Z
Tony DeStefano
<p>I'm trying to index some asset volumes that I'm creating in a migration. These are local volumes which may already contain files. </p>

<p>I'm hoping to avoid the step where I have to manually update the asset indices after creating volumes.</p>

<p>The following code does not seem to perform the index, am I missing a step? I've studied the controller used by Utilities but I can't see where I'm going wrong.</p>

<pre><code>    $volumeId = Craft::$app-&gt;volumes-&gt;getVolumeByHandle('myVolume')-&gt;id;

    $indexer = Craft::$app-&gt;getAssetIndexer();

    $sessionId = $indexer-&gt;getIndexingSessionid();

    $indexer-&gt;processIndexForVolume($sessionId,$volumeId);
</code></pre>

<p>Any help is much appreciated</p>

CC BY-SA 4.0
2018-12-06T17:57:14.850Z
Did you ever find a solution to this?
ryanpcmcquen
CC BY-SA 4.0
2018-12-11T10:19:19.490Z
Hey,  no I never did. I've tried digging through the services Craft itself uses for this but I don't have enough experience with that side of the application to extract anything of use. It would be nice if there was a service you could just hit but it doesn't appear to be that simple.
Piaras Hoban
CC BY-SA 4.0
2018-12-14T16:10:08.893Z
Have you tried downloading and reverse engineering plugins that need to do something similar? I tend to start there when there isn't clear documentation or SO questions to help me out. Check out the plugin store and see if asset related plugins have Craft 2 versions. The Craft 3 version would likely need to do some migrations.
Chattervast
<craft3><php><migration>
Update Asset Index in Migration
# Update Asset Index in Migration

(Asked by: username_0 on 2018-05-23)

I'm trying to index some asset volumes that I'm creating in a migration. These are local volumes which may already contain files. 
I'm hoping to avoid the step where I have to manually update the asset indices after creating volumes.
The following code does not seem to perform the index, am I missing a step? I've studied the controller used by Utilities but I can't see where I'm going wrong.
    $volumeId = Craft::$app->volumes->getVolumeByHandle('myVolume')->id;

    $indexer = Craft::$app->getAssetIndexer();

    $sessionId = $indexer->getIndexingSessionid();

    $indexer->processIndexForVolume($sessionId,$volumeId);

Any help is much appreciated

**Tags:** craft3, php, migration

> **Comments:**
> **username_1**: Did you ever find a solution to this?  
> **username_0**: Hey,  no I never did. I've tried digging through the services Craft itself uses for this but I don't have enough experience with that side of the application to extract anything of use. It would be nice if there was a service you could just hit but it doesn't appear to be that simple.  
> **username_2**: Have you tried downloading and reverse engineering plugins that need to do something similar? I tend to start there when there isn't clear documentation or SO questions to help me out. Check out the plugin store and see if asset related plugins have Craft 2 versions. The Craft 3 version would likely need to do some migrations.  

---

## 1 answers

### Answer by username_3 on 2019-01-30. Score: 3

As of 3.1.2 you can now index assets via the cli tool:
./craft index-assets/all 

OR
./craft index-assets/one {handle}


---

