Gigya Job Openings

ds.search Examples REST

Skip to end of metadata
Go to start of metadata

Description

This page shows examples using the ds.search REST API.

Examples

  1. Examples of searching objects by UID:
    1.1 First associate an object to a UID using ds.store:

    ds.store({
        data:{bands:{rock:'zeppelin', jazz:'coltrain'}},
        type:'music',
        oid:'auto',
        UID='_gid_PJwNlJ5N11BLPAXIls8ty6mDdjQD6XzMT2+N/zrztsM='
    });

    1.2 Search objects by UID:

    SELECT * FROM music WHERE UID='_gid_PJwNlJ5N11BLPAXIls8ty6mDdjQD6XzMT2+N/zrztsM='

    1.3 Response to the query:

    {
      "results": [
        {
          "data": {
            "bands": {
              "jazz": "coltrain",
              "rock": "zeppelin"
            }
          },
          "lastUpdated": 1419426021590,
          "created": 1419426021590,
          "lastUpdatedTime": "2014-12-24T13:00:21Z",
          "createdTime": "2014-12-24T13:00:21Z",
          "UID": "_gid_PJwNlJ5N11BLPAXIls8ty6mDdjQD6XzMT2+N/zrztsM=",
          "oid": "3dfaa6836ac64711837cb98e3893007a"
        }
      ],
      "objectsCount": 1,
      "totalCount": 1,
      "statusCode": 200,
      "errorCode": 0,
      "statusReason": "OK",
      "callId": "d126af8d2d21446d867fa67f61cef832"
    }
    
  2. Example of a count of objects:

    SELECT COUNT(*) FROM music

    Response to the query:

    {"results": [{ "count(*)": 1527}],
    		"objectsCount": 1,
    		"totalCount": 1527,
    		"statusCode": 200,
    		"errorCode": 0,
    		"statusReason": "OK",
    		"callId": "11111"}	
  3. Example of a query using limit and start.  The query lists 3 fields in a music object where the musician is "U2".  The query is limited to 5 results, starting with the 100th valid user.   

    SELECT music.trackName, music.album, music.format FROM music WHERE music.musician="U2" LIMIT 5 START 100

    Response to the query:

     {"results": [  
         {"music": {"trackName": "I will follow", "format": "mp3"} },  
         {"music": {"trackName": "Into the Heart", "album": "Boy", "format": "mp3" } }, 
         {"music": {"trackName": "The Ocean", "album": "Boy" } }, 
         {"music": {"trackName": "A Day Without Me", "album": "Boy", "format": "mp3" } }, 
         {"music": {"trackName": "Shadowns and Tall Trees", "album": "Boy", "format": "mp3" } }  ], 
     "objectsCount": 5, 
     "totalCount": 1840, 
     "statusCode": 200, 
     "errorCode": 0, 
     "statusReason": "OK", 
     "callId": "2222" }
  4. Example of a query using as. The query lists 3 fields in a music object where the musician is "U2".  The query will return 5 results, starting with the 100th valid user.   

    SELECT music.trackName AS Track, music.album AS Disk, music.format AS Extension FROM music WHERE music.musician="U2" LIMIT 5 START 100

    Response to the query:

     {"results": [  
         {"music": {"Track": "I will follow",                   "Extension": "mp3" } },  
         {"music": {"Track": "Into the Heart",   "Disk": "Boy", "Extension": "mp3" } }, 
         {"music": {"Track": "The Ocean",        "Disk": "Boy"                   } }, 
         {"music": {"Track": "A Day Without Me", "Disk": "Boy", "Extension": "mp3" } }, 
         {"music": {"Track": "Shadows and Trees","Disk": "Boy", "Extension": "mp3" } }  ], 
     "objectsCount": 5, 
     "totalCount": 1840, 
     "statusCode": 200, 
     "errorCode": 0, 
     "statusReason": "OK", 
     "callId": "2222" }
  5. Example of a query using contains. This query counts pictures of "Madrid":

    SELECT COUNT(*) FROM album WHERE album.photo.title CONTAINS "Madrid"
    Response to the query
    { "results": [ { "count(*)": 28 } ],
      "objectsCount": 1,
      "totalCount": 28,
      "statusCode": 200,
      "errorCode": 0,
      "statusReason": "OK",
      "callId": "3333" }
  6. Example of a query using regex. This query searches for photos starting with the letter "A".

    SELECT album.photo.title FROM album WHERE album.photo.title = regex('A.*')

    Response to the query:

    {  
    "results": [{   
        "album": {
            "photo": {
                "title:"At the party", 
                "title": "At the sea", 
                "industry": "Computer Software" }
        } 
    }, { 
        "profile": { 
            "name": "Andy Goslan",  
            "religion": "Atea", 
            "industry": "Computer Software" } 
        }  
    ],
    "objectsCount": 2, 
    "totalCount": 2, 
    "statusCode": 200,
    "errorCode": 0, 
    "statusReason": "OK", 
    "callId": "1234567" 
    }