0

I have multiple subsites and each subsite has a list called "Vidoes". it has a content type called "Video Fields". I would like to search based on the content types above using search api with rest. It should result all the items present in all the sites and subsistes. Basically the user will give the meta data as input

Can any one help on the same

3
  • Find your content type internal name and use "SPContentType=[contentTypeName]" in your query
    – YogaPanda
    Mar 15, 2018 at 16:43
  • What is reason for using REST rather than default Search? Are you planning to use the result in code? Mar 15, 2018 at 18:59
  • Actually i want to fetch them in sharepoint Grid and write a jquery filter Mar 16, 2018 at 7:23

1 Answer 1

1

REST API:

    var searchApi = '/_api/search/query?querytext=%27ContentType:"Video Fields"'
    var selectedParameter = '&trimduplicates=false&rowlimit=%27500%27&selectproperties=%27NameOWSTEXT%27';
    var searchQuery = _spPageContextInfo.siteAbsoluteUrl +searchApi + ' %27' + selectedParameter
    var query = "";
    $.ajax({
        url: searchQuery,
        type: "GET",
        headers: {
            "Accept": "application/json;odata=verbose"
        },
        async: false,
        success: function (data, textStatus, xhr) 
        {
           console.log(data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results);

        },
        error: function (data) {
            console.log(data);
        }
    }); 
9
  • Thanks DeepMala . I was able to search based on content type. But why can't i see the Site Columns assoicated with that content type. For example i have Title,VideoUrl,VideoId assoicated with that content type. But i can't see those Items. Can you plse help in this regard Mar 17, 2018 at 4:39
  • You need specify these site columns managed properties under selectproperties parameter
    – Deepmala
    Mar 19, 2018 at 3:27
  • Actually when i use select properties it is returning 'Null' Even though my list has data for that field. Any idea on the same Mar 19, 2018 at 13:47
  • 1
    I think I am missing the OWSTEXT. it is working fine Mar 19, 2018 at 14:27
  • How can we sort by ListItemID. This is my last question Mar 19, 2018 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.