#!/bin/bash

# Clean
curl -XDELETE 'http://localhost:9200/null?pretty'

# Create index 
curl -XPOST 'http://localhost:9200/null?pretty'

# Create mapping
curl -XPOST 'http://localhost:9200/null/type/_mapping?pretty' -d '
{
   "type":{
      "properties":{
         "list":{
            "properties":{
               "x" : {"type" : "string", "null_value" : "-1"}
            }
         }
      }
    }
}'

# Echo mapping
curl -XGET 'http://localhost:9200/null/type/_mapping?pretty'

# Insert document with an array
curl -XPOST 'http://localhost:9200/null/type/?pretty&refresh' -d '
{
   "list":[
      {
         x: "1"
      },
      { 
         x: null 
      },
      {
         x: "2"
      }
   ] 
}'

# Should return a null
curl -XGET 'http://localhost:9200/null/type/_search?pretty' -d '
{
   "fields": ["list.x"],
   "query":{
        "match_all":{}
      }
   }
}'