Defining a Schema for an Array

Here is how to write an array schema. For simplicity let's assume that we want to send a data in this form:

{
  "members": [
    {
      "fullName": "Homer Simpson",
      "email": "homer@acme.org"
    },
    {
      "fullName": "Bart Simpson",
      "email": "bart@acme.org"
    }
  ]
}

For this data to be processed we would need to write the following schema:

{
  "type": "object",
  "properties": {
    "members": {
      "type": "array",
      "required": true,
      "properties": {
        "fullName": {
          "type": "string",
          "required": true
        },
        "email": {
          "type": "string",
          "required": true
        }
      }
    }
  }
}

The difference is in using the items vs. properties. Default draft-03 JSON Schema uses items, however our platform does not accept this method of definition. You should always use properties instead.

Array processing Limitations

elastic.io platform has two limitations regarding to the array processing:

1
No naked arrays will be processed
2
Only array of objects will be processed

No naked arrays

The following example demonstrates what we call a naked object. The root of the JSON is array:

[ 
    { 
        "email" : "info@acme.org" 
    },
    { 
        "email" : "noreply@acme.org" 
    }  
]

Our mapper will not be able to map naked objects. That's why you will need to use a JSON object in the root with a property holding your array, as shown in the following example:

{
    "values": [
        { 
            "email" : "info@acme.org" 
        },    
        { 
            "email" : "noreply@acme.org" 
        }  
    ]
}

Only array of objects

elastic.io would not process the primitive types in arrays therefore it is highly advised to represent them in an object array. For example if an array of data [1,2,3] needs to be processed then it would need to be sent as an object in the following way:

{
  "numbers" : [
    {
      "numeric_value": 1
    },
    {
      "numeric_value": 2
    },
    {
      "numeric_value": 3
    }
  ]
}