none
How to get the search results where a managed property is not empty (or is not null)?

    Question

  • I have a lot of sites with an indexed property bag entry mapped to a managed property of type 'string'. What KQL can I create to query all the sites where this managed property value is NOT empty? E.g. I want to get all the sites where the property bag entry exists and has a value in it.

    Please, mark as answer, if this helps.

    Wednesday, July 11, 2018 3:34 PM

Answers

All replies

  • Hi Vadim Maximov,

    You could get the result from the indexed property bag by PowerShell command.

    You can loop through the sites and check if there is result from the indexed property bag.

    There is a demo for your reference:

    $myWeb = Get-SPWeb "http://sp:20971"
    
    foreach ($prop in $myWeb.IndexedPropertyKeys.GetEnumerator() | Sort-Object -Property Name) {
    
                        
    
                               if(($prop.Name -eq "test1") -and ($prop.Value -ne $null ))
    
                       {  Write-Host " - " $prop.Name "->" $prop.Value
    
                                                                      
    
                                                                       }
    
    }


    Best regards,

    Sara Fan


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, July 12, 2018 7:40 AM
    Moderator
  • Thanks, but the question still remains: what KQL to use to get this info?

    I am implementing a grid in an application that shows the search results. The uses can filter/sort the columns in the grid. The columns are the managed property values coming from the search (indexed property bag entries). And the sites which do not contain the property bag entries or which are empty, are shown as the rows with empty columns. I want to filter these values at the step of querying SharePoint search, i.e. at the step of KeywordQuery object creation.

    It seems like KQL does not support a term like NOT NULL or ManagedProperty <> "" to get not empty values.



    Thursday, July 12, 2018 11:37 AM
  • Hi Vadim Maximov,

    Yes, the KQL does not support to filter the managed properties which is not empty.

    if you want to filter the managed property which is not empty, I suggest you use custom code to achieve it.

    More references:

    Programmatically working with Keyword Search Queries in SharePoint 2013.

    https://blog.mastykarz.nl/programmatically-working-keyword-search-queries-sharepoint-2013/

    Keyword Query in SharePoint Search.

    http://adicodes.com/keyword-query-in-sharepoint-search/

    Best regards,

    Sara Fan


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by Vadim Maximov Monday, July 16, 2018 11:53 AM
    Monday, July 16, 2018 10:03 AM
    Moderator