Answers.Body: <p>You could try and listen to <a href="http://buildwithcraft.com/classreference/services/AssetsService#onBeforeSaveAsset-detail" rel="nofollow"><code>onBeforeSaveAsset</code></a> events instead of <code>onSaveAsset</code>. With <a href="http://buildwithcraft.com/classreference/services/AssetsService#onBeforeSaveAsset-detail" rel="nofollow"><code>onBeforeSaveAsset</code></a> you can modify the asset model before being saved, so you don't have to do that manually.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-05T17:02:52.157Z
Answers.LastActivityDate: 2015-05-05T17:02:52.157Z
Answers.UserDisplayName: carlcs
Body: <p>I use an assets.onSaveAsset Event in my plugin to update a field with the IPTC-Data of the image. </p>
  
  <pre><code>  $asset-&gt;getContent()-&gt;keywords = $this-&gt;get_iptc_keywords($imgPath);
    craft()-&gt;elements-&gt;saveElement($asset);
  </code></pre>
  
  <p>It updates the field values of the asset, but it does not update the search index. When i resave the asset, the searchindex table is updatet and works. Is this a craft bug and is there a craft way to update the search index for a single element (not the full index). Otherwise do i need to update the index by writing plain sql update/insert statements? Thanks for any help...</p>
  
Tags: <plugins><events>
Title: Update search index after assets.onSaveAsset Event
ThreadText: # Update search index after assets.onSaveAsset Event
  
  (Asked by: username_0 on 2015-05-04)
  
  I use an assets.onSaveAsset Event in my plugin to update a field with the IPTC-Data of the image.
  
  ```
    $asset->getContent()->keywords = $this->get_iptc_keywords($imgPath);
    craft()->elements->saveElement($asset);
  
  ```
  
  It updates the field values of the asset, but it does not update the search index. When i resave the asset, the searchindex table is updatet and works. Is this a craft bug and is there a craft way to update the search index for a single element (not the full index). Otherwise do i need to update the index by writing plain sql update/insert statements? Thanks for any help...
  
  **Tags:** plugins, events
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-05-05. Score: 1 | Accepted answer
  
  You could try and listen to [`onBeforeSaveAsset`](http://buildwithcraft.com/classreference/services/AssetsService#onBeforeSaveAsset-detail) events instead of `onSaveAsset`. With [`onBeforeSaveAsset`](http://buildwithcraft.com/classreference/services/AssetsService#onBeforeSaveAsset-detail) you can modify the asset model before being saved, so you don't have to do that manually.
  
  
  ---
  
  