SharePoint search query > Json gives al lot of unnecessary data

Regular Contributor

I have to (jquery) rest searches. The first one:

       url: `${this.props.siteurl}/_api/web/lists/getbytitle('EmployeeList')/items`,
       type: "GET",
       headers:{'Accept': 'application/json; odata=verbose;'},
       success: function(resultData) {...... bla bla

This one gives a nice clean/small json results. I get my field using "resultData.d.results"


My second query is this:

        url: "'ContentType:test_matters'&selectproperties='RefinableString10%2cCreatedBy%2cCreated'&rowlimit=500'",
        type: "GET",
        headers:{'Accept': 'application/json; odata=verbose;'},                     
        success: function(resultData) {..... blabla

This one gives me a huge json result with too much data. I have to get my data using this:

This gives me some problems. Ain't it possible to have the output from the second query in the same format as the first one?
Thanks, Mike
2 Replies
best response confirmed by Mike Jansen (Regular Contributor)

Hey Mike,


In your first REST request, you're getting data from the list. The second one is a search API call.

The search data is as it is. It's absolutely normal thing. Nothing to do with it. But resulted data can be reduced to more friendly format on the client side with something like:


var endpoint = _spPageContextInfo.webServerRelativeUrl + "/_api/search/query?querytext='*'";
    url: endpoint,
    type: "GET",
    headers: {
        'Accept': 'application/json; odata=verbose;'
    success: function(response) {
        var results = response.d.query.PrimaryQueryResult
            .map(function(row) {
                return row.Cells.results.reduce(function(res, cell) {
                    res[cell.Key] = cell.Value;
                    return res;
                }, {});

Two additional pieces of advice:

- There are `nometadata` and `minimalmetadata` OData modes which can reduce response package;

  - `nometadata` and `minimalmetadata` are available in SP 2016 and SPO (2013 requires some installation on server side);

  - The output format is different for different modes, this should be taken into consideration.

- Helper libraries like PnP JS Core can work with search too, it's easier to code with such libs, also, no jQuery needed for ajax calls in this cases.