How to return item metadata from search API
I am trying to search my sharepoint site by metadata to return all files with matching metadata in the site.
My understanding is you can't search by metadata specifically, only in a general search (which searches the metadata).
So I have a query as follows:
POST: https://graph.microsoft.com/v1.0/search/query
With body:
{
"requests": [
{
"entityTypes": [
"listItem"
],
"query": {
"queryString": "ABC999"
},
"fields": [
"id",
"listId",
"author",
"title",
"JobNo"
]
}
]
}
I am trying to get my custom column "JobNo" in the list - but no matter what I do the column is not returned.
"value": [
{
"searchTerms": [
"abc999"
],
"hitsContainers": [
{
"hits": [
{
"hitId": "69868747-bae4-4030-8ecb-789c7b6605f8",
"rank": 1,
"summary": "<c0>ABC999</c0> 1 1290 0 {69868747-BAE4-4030-8ECB-789C7B6605F8},7<ddd/>",
"resource": {
"@odata.type": "#microsoft.graph.listItem",
"fields": {
"id": "AAAAAGtrIFaMpeBNi5Q5UuCSS4YHABFIEmmOvHVOl9Wj_bW_4J4AAAAAAWAAABFIEmmOvHVOl9Wj_bW_4J4ABMe7KkEAAA2",
"listId": "b14c2192-d205-4bde-8d3c-6b52d5bd0dd6",
"author": "Oliver;Owner Name",
"title": "Service--v2---1-"
},
"id": "69868747-bae4-4030-8ecb-789c7b6605f8"
}
},
{
"hitId": "7893eea7-3ba0-4943-843a-40f71f33fb21",
"rank": 2,
"summary": "<c0>ABC999</c0> P002 1 1065 0 {7893EEA7-3BA0-4943-843A-40F71F33FB21<ddd/>",
"resource": {
"@odata.type": "#microsoft.graph.listItem",
"fields": {
"id": "AAAAAGtrIFaMpeBNi5Q5UuCSS4YHABFIEmmOvHVOl9Wj_bW_4J4AAAAAAWAAABFIEmmOvHVOl9Wj_bW_4J4ABQXVWrQAAA2",
"listId": "a5aac080-1fa9-4a2c-bf7f-f061380a53bc",
"author": "Oliver;Owner Name",
"title": "Service New (v1)"
},
"id": "7893eea7-3ba0-4943-843a-40f71f33fb21"
}
}
],
"total": 2,
"moreResultsAvailable": false
}
]
}
],
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}
When I query the list directly, you can see the column is indeed in that list.
...snipped
{
"columnGroup": "Custom Columns",
"description": "",
"displayName": "JobNo",
"enforceUniqueValues": false,
"hidden": false,
"id": "4966126c-c248-4fe0-8324-65e500ea466a",
"indexed": false,
"name": "JobNo",
"readOnly": false,
"required": false,
"text": {
"allowMultipleLines": false,
"appendChangesToExistingText": false,
"linesForEditing": 0,
"maxLength": 255
}
},
... snipped
In the documentation here it says you can query custom columns. https://learn.microsoft.com/en-us/graph/api/resources/search-api-overview?view=graph-rest-1.0#get-selected-properties
It also says here (fields section) you can prefix with label_ to get the property. (this also doesn't work).
https://learn.microsoft.com/en-us/graph/api/resources/searchrequest?view=graph-rest-1.0
What am I missing here? This all reads like I should be able to return the document metadata from the search.
Thanks
~Ben