Preference Header with Post

Elastic Search Rest services accept a preference header to define if a query shall be transient, stored, return results, or return a describe on itself.

Transient

Transient preference is used for querying with post without saving the query. Please note that Post with transient preference will not generate any pagination links.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries

Example Request Payload

{   
    "name":"demo json parser",
    "entity":"Account",
    "keywords":"parser",
    "sort": [{ "attribute":"PartyUniqueName","direction":"ascending"}],
    "fields":["PartyUniqueName","PrimaryAddress"],
    "q":{"op": "$all" , "attribute": "PartyUniqueName", "value": "Technologies United"},
    "excludeFields" : ["PrimaryIndustry"],
    "aggregations":{
        "PrimaryIndustry":{
            "ignore": true,
            "terms":{
                "attribute": "PrimaryIndustry",
                "maxNumberOfBuckets" : 5,
                "includeTerms":["1022","1012"],
                "excludeTerms":["1234"],
                "other": true,   
                "missing": true,
                "localize": true
            }
        },
        "CreationDate":{
            "ignore":true,
            "range":{
                "attribute":"CreationDate",
                "ranges":[
                    {"key": "ThisQuarter", "from": "now/m-3m", "to": "now"},
                    {"key": "NextQuarter", "from": "now", "to": "now/m+3m"},
                    {"key": "ThisYear", "from": "now/y", "to": "now/y+1y"},
                    {"key": "LastQuarter", "from": "now/m-6m", "to": "now/m-3m"},
                    {"key": "LastYear", "from": "now/y-1y", "to": "now/y"}
                ]
            }
        }
    },
    "keywordsFields":["PrimaryIndustry"],
    "applicationData": {
                "461e5791-9f15-4cd1-b5cd-19e8480cbce6":{"hello":{"Nice":"Work"}}
            },
    "highlights" : {
        "pre": ["<em>"],
        "post": ["</em>"]
        "fields":["PartyUniqueName"]
    }
}

Stored

Stored preference will create a new query and resultant query would be displayed.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries

Example Request Payload

{   
    "name":"demo json parser",
    "entity":"Account",
    "keywords":"parser",
    "sort": [{ "attribute":"PartyUniqueName","direction":"ascending"}],
    "fields":["PartyUniqueName","PrimaryAddress"],
    "q":{"op": "$all" , "attribute": "PartyUniqueName", "value": "Technologies United"},
    "excludeFields" : ["PrimaryIndustry"],
    "aggregations":{
        "PrimaryIndustry":{
            "ignore": true,
            "terms":{
                "attribute": "PrimaryIndustry",
                "maxNumberOfBuckets" : 5,
                "includeTerms":["1022","1012"],
                "excludeTerms":["1234"],
                "other": true,   
                "missing": true,
                "localize": true
            }
        },
        "CreationDate":{
            "ignore":true,
            "range":{
                "attribute":"CreationDate",
                "ranges":[
                    {"key": "ThisQuarter", "from": "now/m-3m", "to": "now"},
                    {"key": "NextQuarter", "from": "now", "to": "now/m+3m"},
                    {"key": "ThisYear", "from": "now/y", "to": "now/y+1y"},
                    {"key": "LastQuarter", "from": "now/m-6m", "to": "now/m-3m"},
                    {"key": "LastYear", "from": "now/y-1y", "to": "now/y"}
                ]
            }
        }
    },
    "keywordsFields":["PrimaryIndustry"],
    "applicationData": {
                "461e5791-9f15-4cd1-b5cd-19e8480cbce6":{"hello":{"Nice":"Work"}}
            },
    "highlights" : {
       "pre": ["<em>"],
       "post": ["</em>"],
       "fields":["PartyUniqueName"]
    }
}

Query result

Stores the saved search and returns query results.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries

Example Request Payload

{   
    "name":"demo json parser",
    "entity":"Account",
    "keywords":"parser",
    "sort": [{ "attribute":"PartyUniqueName","direction":"ascending"}],
    "fields":["PartyUniqueName","PrimaryAddress"],
    "q":{"op": "$all" , "attribute": "PartyUniqueName", "value": "Technologies United"},
    "excludeFields" : ["PrimaryIndustry"],
    "aggregations":{
        "PrimaryIndustry":{
            "ignore": true,
            "terms":{
                "attribute": "PrimaryIndustry",
                "maxNumberOfBuckets" : 5,
                "includeTerms":["1022","1012"],
                "excludeTerms":["1234"],
                "other": true,   
                "missing": true,
                "localize": true
            }
        },
        "CreationDate":{
            "ignore":true,
            "range":{
                "attribute":"CreationDate",
                "ranges":[
                    {"key": "ThisQuarter", "from": "now/m-3m", "to": "now"},
                    {"key": "NextQuarter", "from": "now", "to": "now/m+3m"},
                    {"key": "ThisYear", "from": "now/y", "to": "now/y+1y"},
                    {"key": "LastQuarter", "from": "now/m-6m", "to": "now/m-3m"},
                    {"key": "LastYear", "from": "now/y-1y", "to": "now/y"}
                ]
            }
        }
    },
    "keywordsFields":["PrimaryIndustry"],
    "applicationData": {
                "461e5791-9f15-4cd1-b5cd-19e8480cbce6":{"hello":{"Nice":"Work"}}
            },
    "highlights" : {
        "pre": ["<em>"],
        "post": ["</em>"],
        "fields":["PartyUniqueName"]
    }
}