2

I'm trying to get the ID of a lookup field when using search api.
My query looks something like this:

/_api/Search/query?querytext='ListId:12345678-1234-1234-1234-123456789012'&selectproperties='Title,Company'

Where Company is the lookup field, in a specific list.

The result looks like this:

<d:element m:type="SP.KeyValue">
  <d:Key>Company</d:Key>
  <d:Value>Some company</d:Value>
  <d:ValueType>Edm.String</d:ValueType>
</d:element>

I have created a managed property which looks like this: enter image description here

6
+50

I don't think it's possible. However, you could add the ID as a "column to show" in the List:

enter image description here

after which you will have a corresponding crawled property:

enter image description here

which you then can map to a managed property

enter image description here

After this you can use that managed property to retrieve the id of the linked company:

{
  "__metadata": {
    "type": "SP.KeyValue"
  },
  "Key": "companyid",
  "Value": "2",
  "ValueType": "Edm.String"
}

The column (Company:ID) could be removed from all Views and - using PowerShell even from the DisplayView.

  • Brilliant! It even works with multi lookup. Interesting note; I tested with several fields, the crawled properties was named after fields Title (not InternalName), one was called "SharePoint:ID". I'll leave the question open for a couple of days before you get the bounty, but so far I'd be surprised to find a better solution :) – eirikb Sep 5 '16 at 19:34

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.