Guruleni
Guruleni

Reputation: 566

Available Fields for Sharepoint Search Query on Microsoft Graph API

I'm using the Graph API to make a global search in my sharepoint website, and I need to retrieve some specific fields. I didn't find any documentation that specifies the available fields that I can use for the fields property on my payload, only a documentation for specific document library search.

I have to use the global search because my search needs to access all the document libraries on my sharepoint web site.

The field that I wanted to get from the request is the version of the document in the list. I could add this field in sharepoint, and my view is displaying the version values, but the request does not take this value. I'm using this request below:

Endpoint: https://graph.microsoft.com/v1.0/search/query

Payload:

"requests": [
        {
            "entityTypes": [
                "listItem"
            ],
            "query": {
                "queryString": ""
            },
            "fields": [
                "title",
                "_UIVersionString"
            ]
        }
    ]
}

Response:

{
    "value": [
        {
            "searchTerms": [],
            "hitsContainers": [
                {
                    "hits": [
                        {
                            "hitId": "83C63693-C621-4CFE-B4F7-A36B68AEB421",
                            "rank": 1,
                            "summary": "...",
                            "resource": {
                                "@odata.type": "#microsoft.graph.listItem",
                                "fields": {
                                    "title": "Calc.22090615231879"
                                }
                            }
                        },
                    ],
                    "total": 1,
                    "moreResultsAvailable": false
                }
            ]
        }
    ],
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}

The name of the field I'm using in the payload that corresponds to the version is _UIVersionString, where I got it from the specific list search request, using the https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$expand=fields endpoint. But sadly, the version is not appearing on my search result.

Is there some documentation I could use to see a list of available fields for this request? I'm trying to find it in MS GraphAPI documentation, but it looks be a big real encyclopedia.

Do you know the name of the field that corresponds to the version?

Thanks a lot!

Other information:

Sharepoint Version: Sharepoint Web (Online)
Type of the lists: Document Library
Lists version configuration:
- Require content approval for submitted items?: No
- Create a version each time you edit a file in this document library?: Create Major Versions
- Require documents to be checked out before they can be edited?: No

Upvotes: 3

Views: 1460

Answers (1)

devil_inside
devil_inside

Reputation: 450

Since Graph is using there managed properties from sharepoint you can try "UIVersionStringOWSTEXT".

{
    "requests": [
        {
            "entityTypes": [
                "listItem"
            ],
            "query": {
                "queryString": "test"
            },
            "fields": [
                "title",
                "UIVersionStringOWSTEXT"
            ]
        }
    ]
}

The results look like

{
    "value": [
        {
            "searchTerms": [
                "test"
            ],
            "hitsContainers": [
                {
                    "hits": [
                        {
                            "hitId": "GUID",
                            "rank": 1,
                            "summary": "test",
                            "resource": {
                                "@odata.type": "#microsoft.graph.listItem",
                                "fields": {
                                    "title": "test",
                                    "uiVersionStringOWSTEXT": "1.0"
                                }
                            }
                        }
                    ],
                    "total": 1,
                    "moreResultsAvailable": false
                }
            ]
        }
    ],
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}

In my tenant this property was already created. I guess it is by default. If your search schema does not have this managed property you can create it and name it like you wish. Map it to the crawled property "ows_q_TEXT__UIVersionString" and make sure your managed property is set to "retrievable".

enter image description here

Upvotes: 1

Related Questions