3

I am new to Search Query Tool,

I have a team site, which contain multiple list with the same content type named "Ticket",

The first problem i have encountered, is I need to collect all the items from all these lists (which are similar and have the same Content Type), into one place in order to use them as a Data source for reporting later.

So I found that i can work with Search Query Tool, which enable you to create an endpoint and collect in it what you desire.

enter image description here

Question: How can I build a query that get all the items with the ContentType=Ticket ?

2

You'll need to first look up the ContentTypeID of your ContentType. There are multiple ways to find the ID of a site-level Content Type: using the REST API, using PowerShell, or carefully parsing it from the URL query string after you browse to that ContenType's config page in the browser.

Once you have that ID, you have to understand that every time you add that ContentType to a List or Library, SharePoint technically creates its own derived type from the site-level type by appending additional numbers on to the end of the ID to ensure it is unique. So, you will want to append the wildcard character to the end for your search query to find all derived uses of your ContentType, such as querytext='ContentTypeId:YourSiteContentTypeIdHere*'

For example, if your ContentType ID is 0x0100AEC702D446F8F04696C2B7573837C451, then the following query would get all items from all lists that are using a content type derived from that type:

https://bbsdz.sharepoint.com/_api/search/query?querytext='ContentTypeId:0x0100AEC702D446F8F04696C2B7573837C451*'

| improve this answer | |
  • Alright, I totally understand your answer, now how can I continue with the solution and bring back the items with the specified content type and show them in a random page or something like that ! – AIMEN BOULAHIA Feb 2 at 15:07
  • To display items in some page you need to add webpart "Content Search Web Part" on that page. Edit that web part query in web part properties.In query you put that ContentTypeId:0x0100AEC702D446F8F04696C2B7573837C451 – Marko Tica Feb 3 at 11:36
  • still not clear for me ! – AIMEN BOULAHIA Feb 3 at 14:12
  • 2
    @MarkoTica 's comment is explaining that once you get your query exactly how you want it in the query tool, you will need to use the "Content Search Web Part" to put those results on a classic page. If you are using Modern pages, you will need to use the "Highlighted Content WebPart" configured with a "custom" query, and then you can paste in the query you built in the tool. – willman Feb 3 at 14:47
  • 1
    For Modern pages use this steps in Highlighted Content WebPart joannecklein.com/2018/09/12/… If you're having trouble filtering by the Name of your Content Type, make sure you're using the 'SPContentType' managed property rather than 'ContentType'. – Marko Tica Feb 3 at 15:14
2

It the content type name is "Ticket" you can use a contains query like ContentType:Ticket. The ContentType Managed Property is populated with the name of the content type. Sometimes it have spaces padding it so I have found contains (using the colon) works best.

| improve this answer | |
  • I did not understand your answer Mr Matthew, you mean that i should work with KQL in the modern experience directly ? – AIMEN BOULAHIA Feb 3 at 14:13
  • 1
    It appears that you are using the query ContentType=Ticket. I sugest you change it to ContentType:Ticket. You can also try the SPContentType managed property. – Matthew McDermott Feb 4 at 12:39

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.