I am looking for a master index query that will return the latest version of any item. In the solr index there is a field call _latestversion. But when I add that to my query, I get the error

Find-Item : No property or field '_latestversion' exists in type 'SearchResultItem'

Here is my query

$items = Find-Item -Index sitecore_master_index -Where '(TemplateId=@0 Or TemplateId=@1) And Path.Contains(@2) And _latestversion=true' -WhereValues $clubTemplateId, $wogTemplateId, $roothPath | Initialize-Item

I could use a Get-Item for each result, but that is overkill.


If you want to use _latestVersion with Find-Item command then you will need to use -Criteria instead of -Where because -Where uses SearchResultItem class to map the properties whereas -Criteria work directly against Solr fields.

Example -

$clubTemplateId = New-Object Sitecore.Data.ID::new("{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}")  
$wogTemplateId = New-Object Sitecore.Data.ID::new("{716FD1F8-FB35-40FA-A144-B0A6BA96E967}") 

$roothPath = "/sitecore/content"    

$idHelper = New-Object Sitecore.ContentSearch.Utilities.IdHelper

$criteria = @(
                @{Filter = "Contains"; Field = "_fullpath"; Value = $roothPath},
                @{Filter = "ContainsAny"; Field = "_template"; Value = [string[]]@($idHelper::NormalizeGuid($clubTemplateId), $idHelper::NormalizeGuid($wogTemplateId))},
                @{Filter = "Equals"; Field = "_latestversion"; Value = "1"}

$items =Find-Item -Index sitecore_master_index -Criteria $criteria | Initialize-Item

Write-Host $items.Length
| improve this answer | |

If you are using SPE 6.0 this might work for you. Introduced with this issue.

class ExtendedSearchResultItem : SearchResultItem

$props = @{
    Index = "sitecore_master_index"
    Where = "IsLatestVersion == @0"
    WhereValues = $true
    QueryType = [ExtendedSearchResultItem]

Find-Item @props -First 10
| improve this answer | |
  • Wow that is awesome Mike. – Chris Auer Oct 1 '19 at 20:11
  • @Michael has SPE 6.0 released? It's not available in the marketplace. Can you please provide a link to download it? – Surya Oct 2 '19 at 16:58
  • 1
    Yes it has been released on GitHub. Please view the release page for more details. github.com/SitecorePowerShell/Console/releases – Michael West Oct 2 '19 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.