You are viewing the documentation for a prerelease version.

Example Data

    +

    The Analytics documentation uses two example collections, Commerce and TinySocial.

    Commerce

    The Commerce example data is used in most of the examples for the N1QL for Analytics Language Reference. It consists of two collections: customers and orders.

    To install the Commerce example data, refer to Install the Commerce Example Data below.

    Customers

    The customers collection contains the following data:

    [
        {
            "custid": "C13",
            "name": "T. Cody",
            "address": {
                "street": "201 Main St.",
                "city": "St. Louis, MO",
                "zipcode": "63101"
            },
            "rating": 750
        },
        {
            "custid": "C25",
            "name": "M. Sinclair",
            "address": {
                "street": "690 River St.",
                "city": "Hanover, MA",
                "zipcode": "02340"
            },
            "rating": 690
        },
        {
            "custid": "C31",
            "name": "B. Pruitt",
            "address": {
                "street": "360 Mountain Ave.",
                "city": "St. Louis, MO",
                "zipcode": "63101"
            }
        },
        {
            "custid": "C35",
            "name": "J. Roberts",
            "address": {
                "street": "420 Green St.",
                "city": "Boston, MA",
                "zipcode": "02115"
            },
            "rating": 565
        },
        {
            "custid": "C37",
            "name": "T. Henry",
            "address": {
                "street": "120 Harbor Blvd.",
                "city": "Boston, MA",
                "zipcode": "02115"
            },
            "rating": 750
        },
        {
            "custid": "C41",
            "name": "R. Dodge",
            "address": {
                "street": "150 Market St.",
                "city": "St. Louis, MO",
                "zipcode": "63101"
            },
            "rating": 640
        },
        {
            "custid": "C47",
            "name": "S. Logan",
            "address": {
                "street": "Via del Corso",
                "city": "Rome, Italy"
            },
            "rating": 625
        }
    ]

    Orders

    The orders collection contains the following data:

    [
        {
            "orderno": 1001,
            "custid": "C41",
            "order_date": "2020-04-29",
            "ship_date": "2020-05-03",
            "items": [
                {
                    "itemno": 347,
                    "qty": 5,
                    "price": 19.99
                },
                {
                    "itemno": 193,
                    "qty": 2,
                    "price": 28.89
                }
            ]
        },
        {
            "orderno": 1002,
            "custid": "C13",
            "order_date": "2020-05-01",
            "ship_date": "2020-05-03",
            "items": [
                {
                    "itemno": 460,
                    "qty": 95,
                    "price": 100.99
                },
                {
                    "itemno": 680,
                    "qty": 150,
                    "price": 8.75
                }
            ]
        },
        {
            "orderno": 1003,
            "custid": "C31",
            "order_date": "2020-06-15",
            "ship_date": "2020-06-16",
            "items": [
                {
                    "itemno": 120,
                    "qty": 2,
                    "price": 88.99
                },
                {
                    "itemno": 460,
                    "qty": 3,
                    "price": 99.99
                }
            ]
        },
        {
            "orderno": 1004,
            "custid": "C35",
            "order_date": "2020-07-10",
            "ship_date": "2020-07-15",
            "items": [
                {
                    "itemno": 680,
                    "qty": 6,
                    "price": 9.99
                },
                {
                    "itemno": 195,
                    "qty": 4,
                    "price": 35
                }
            ]
        },
        {
            "orderno": 1005,
            "custid": "C37",
            "order_date": "2020-08-30",
            "items": [
                {
                    "itemno": 460,
                    "qty": 2,
                    "price": 99.98
                },
                {
                    "itemno": 347,
                    "qty": 120,
                    "price": 22
                },
                {
                    "itemno": 780,
                    "qty": 1,
                    "price": 1500
                },
                {
                    "itemno": 375,
                    "qty": 2,
                    "price": 149.98
                }
            ]
        },
        {
            "orderno": 1006,
            "custid": "C41",
            "order_date": "2020-09-02",
            "ship_date": "2020-09-04",
            "items": [
                {
                    "itemno": 680,
                    "qty": 51,
                    "price": 25.98
                },
                {
                    "itemno": 120,
                    "qty": 65,
                    "price": 85
                },
                {
                    "itemno": 460,
                    "qty": 120,
                    "price": 99.98
                }
            ]
        },
        {
            "orderno": 1007,
            "custid": "C13",
            "order_date": "2020-09-13",
            "ship_date": "2020-09-20",
            "items": [
                {
                    "itemno": 185,
                    "qty": 5,
                    "price": 21.99
                },
                {
                    "itemno": 680,
                    "qty": 1,
                    "price": 20.5
                }
            ]
        },
        {
            "orderno": 1008,
            "custid": "C13",
            "order_date": "2020-10-13",
            "items": [
                {
                    "itemno": 460,
                    "qty": 20,
                    "price": 99.99
                }
            ]
        },
        {
            "orderno": 1009,
            "custid": "C13",
            "order_date": "2020-10-13",
            "items": []
        }
    ]

    Install the Commerce Example Data

    To install the Commerce example data:

    1. First, use the following links to download the example data to your local system.

    2. If necessary, at the command line, use the bucket-create tool to create a bucket for the example Analytics data:

      couchbase-cli bucket-create \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --bucket-type couchbase \
      --bucket-ramsize 100
    3. Use the collection-manage tool to create a scope for the Commerce data:

      couchbase-cli collection-manage \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --create-scope Commerce
    4. Use the collection-manage tool to create a collection for the customers data:

      couchbase-cli collection-manage \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --create-collection Commerce.customers
    5. Similarly, create a collection for the orders data:

      couchbase-cli collection-manage \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --create-collection Commerce.orders
    6. Use the cbimport tool to import the customers data to the Data service:

      cbimport json \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --scope-collection-exp Commerce.customers \
      --format list \
      --generate-key id::#UUID# \
      --dataset file:///path/to/CommerceCustomers.json
    7. Similarly, import the orders data to the Data service:

      cbimport json \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --scope-collection-exp Commerce.orders \
      --format list \
      --generate-key id::#UUID# \
      --dataset file:///path/to/CommerceOrders.json
    8. Now, using the Analytics service via the Analytics Workbench or the cbq shell, create an Analytics scope to shadow the Commerce scope:

      CREATE ANALYTICS SCOPE Commerce IF NOT EXISTS;
    9. Create an Analytics collection for the customers data:

      CREATE ANALYTICS COLLECTION Commerce.customers
        ON analytics.Commerce.customers;
    10. Create an Analytics collection for the orders data:

      CREATE ANALYTICS COLLECTION Commerce.orders
        ON analytics.Commerce.orders;

    The Analytics service ingests the data. You can now use the Commerce scope.

    TinySocial

    The TinySocial example data is used for some of the examples in the builtin function documentation. It consists of two collections: GleambookUsers and GleambookMessages.

    To install the TinySocial example data, refer to Install the TinySocial Example Data below.

    GleambookUsers

    The GleambookUsers collection contains the following data:

    [ {
      "id":1,
      "alias":"Margarita",
      "name":"MargaritaStoddard",
      "nickname":"Mags",
      "userSince":"2012-08-20T10:10:00",
      "friendIds":[2,3,6,10],
      "employment":[{
                      "organizationName":"Codetechno",
                      "start-date":"2006-08-06"
                    },
                    {
                      "organizationName":"geomedia",
                      "start-date":"2010-06-17",
                      "end-date":"2010-01-26"
                    }],
      "gender":"F"
    },
    {
      "id":2,
      "alias":"Isbel",
      "name":"IsbelDull",
      "nickname":"Izzy",
      "userSince":"2011-01-22T10:10:00",
      "friendIds":[1,4],
      "employment":[{
                      "organizationName":"Hexviafind",
                      "startDate":"2010-04-27"
                   }]
    },
    {
      "id":3,
      "alias":"Emory",
      "name":"EmoryUnk",
      "userSince":"2012-07-10T10:10:00",
      "friendIds":[1,5,8,9],
      "employment":[{
                      "organizationName":"geomedia",
                      "startDate":"2010-06-17",
                      "endDate":"2010-01-26"
                   }]
    } ]

    GleambookMessages

    The GleambookMessages collection contains the following data:

    [ {
      "messageId":2,
      "authorId":1,
      "inResponseTo":4,
      "senderLocation":[41.66,80.87],
      "message":" dislike x-phone its touch-screen is horrible"
    },
    {
      "messageId":3,
      "authorId":2,
      "inResponseTo":4,
      "senderLocation":[48.09,81.01],
      "message":" like product-y the plan is amazing"
    },
    {
      "messageId":4,
      "authorId":1,
      "inResponseTo":2,
      "senderLocation":[37.73,97.04],
      "message":" can't stand acast the network is horrible:("
    },
    {
      "messageId":6,
      "authorId":2,
      "inResponseTo":1,
      "senderLocation":[31.5,75.56],
      "message":" like product-z its platform is mind-blowing"
    }
    {
      "messageId":8,
      "authorId":1,
      "inResponseTo":11,
      "senderLocation":[40.33,80.87],
      "message":" like ccast the 3G is awesome:)"
    },
    {
      "messageId":10,
      "authorId":1,
      "inResponseTo":12,
      "senderLocation":[42.5,70.01],
      "message":" can't stand product-w the touch-screen is terrible"
    },
    {
      "messageId":11,
      "authorId":1,
      "inResponseTo":1,
      "senderLocation":[38.97,77.49],
      "message":" can't stand acast its plan is terrible"
    } ]

    Install the TinySocial Example Data

    To install the TinySocial example data:

    1. First, use the following links to download the example data to your local system.

    2. If necessary, at the command line, use the bucket-create tool to create a bucket for the example Analytics data:

      couchbase-cli bucket-create \
      --cluster node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --bucket-type couchbase \
      --bucket-ramsize 100
    3. Use the collection-manage tool to create a scope for the TinySocial data:

      couchbase-cli collection-manage \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --create-scope TinySocial
    4. Use the collection-manage tool to create a collection for the GleambookUsers data:

      couchbase-cli collection-manage \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --create-collection TinySocial.GleambookUsers
    5. Similarly, create a collection for the GleambookMessages data:

      couchbase-cli collection-manage \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --create-collection TinySocial.GleambookMessages
    6. Use the cbimport tool to import the GleambookUsers data to the Data service:

      cbimport json \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --scope-collection-exp TinySocial.GleambookUsers \
      --format list \
      --generate-key id::#UUID# \
      --dataset file:///path/to/GleamBookUsers.json
    7. Similarly, import the GleambookMessages data to the Data service:

      cbimport json \
      --cluster http://node1:8091 \
      --username Administrator \
      --password password \
      --bucket analytics \
      --scope-collection-exp TinySocial.GleambookMessages \
      --format list \
      --generate-key id::#UUID# \
      --dataset file:///path/to/CommerceCustomers.json
    8. Now, using the Analytics service via the Analytics Workbench or the cbq shell, create an Analytics scope to shadow the TinySocial scope:

      CREATE ANALYTICS SCOPE TinySocial IF NOT EXISTS;
    9. Create an Analytics collection for the GleambookUsers data:

      CREATE ANALYTICS COLLECTION TinySocial.GleambookUsers
        ON analytics.TinySocial.GleambookUsers;
    10. Create an Analytics collections for the GleambookMessages collection:

      CREATE ANALYTICS COLLECTION TinySocial.GleambookMessages
        ON analytics.TinySocial.GleambookMessages;

    The Analytics service ingests the data. You can now use the TinySocial scope.