Advertisement
mdumoulin

Smart Traffic ES Mapping

Dec 19th, 2016
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.36 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. DEFAULT_HOST=localhost
  4. DEFAULT_PORT=9200
  5.  
  6. INPUT_DATA_INDEX=raw-data-index
  7. RULE_RUNTIME_EVENT_INDEX=rule-runtime-event-index
  8. AGENDA_EVENT_INDEX=agenda-event-index
  9.  
  10. while getopts "h:p:" opt; do
  11.   case $opt in
  12.     h)
  13.       echo "-h was triggered, Parameter: $OPTARG" >&2
  14.       HOST=$OPTARG
  15.       ;;
  16.     p)
  17.       echo "-p was triggered, Parameter: $OPTARG" >&2
  18.       PORT=$OPTARG
  19.       ;;
  20.     \?)
  21.       printf "Usage: %s [-h hostname] [-p port]\n" $0
  22.       printf "Defaults: \n\thostname:\t${DEFAULT_HOST}\n\tport:\t\t${DEFAULT_PORT}"
  23.       exit 2
  24.       ;;
  25.   esac
  26. done
  27.  
  28. #
  29. if [[ -z ${HOST} ]]; then
  30.     HOST=$DEFAULT_HOST
  31. fi
  32. if [[ -z ${PORT} ]]; then
  33.     PORT=$DEFAULT_PORT
  34. fi
  35.  
  36. printf "ES URL set to: ${HOST}:${PORT}\n"
  37. printf "\n"
  38. printf "Creating '${INPUT_DATA_INDEX}' index mappings...\n"
  39. curl -XDELETE http://${HOST}:${PORT}/${INPUT_DATA_INDEX}
  40. curl -XPUT http://${HOST}:${PORT}/${INPUT_DATA_INDEX} -d '
  41. {
  42. "mappings" : {
  43.    "measurement": {
  44.        "properties" : {
  45.            "timestamp": {
  46.                "type":   "date",
  47.                "format": "epoch_millis"
  48.            },
  49.            "timestamp2": {
  50.                "type":   "date",
  51.                "format": "epoch_millis"
  52.            },
  53.            "sensorId": {
  54.                "type":"string",
  55.                "index": "not_analyzed"
  56.            },
  57.            "speed": {
  58.                "type":"integer"
  59.            }
  60.        }
  61.    }
  62. }
  63. }'
  64. printf "\n"
  65.  
  66. printf "Creating '${RULE_RUNTIME_EVENT_INDEX}' index mappings...\n"
  67. curl -XDELETE http://${HOST}:${PORT}/${RULE_RUNTIME_EVENT_INDEX}
  68. curl -XPUT http://${HOST}:${PORT}/${RULE_RUNTIME_EVENT_INDEX} -d '
  69. {
  70.    "mappings" : {
  71.        "rule-runtime-event" : {
  72.            "properties" : {
  73.                "timestamp": {
  74.                    "type":   "date",
  75.                    "format": "epoch_millis"
  76.                },
  77.                "eventType" : {
  78.                    "type" : "string",
  79.                    "index": "not_analyzed"
  80.                },
  81.                "eventMsg" : {
  82.                    "type" : "string"
  83.                },
  84.                "sensor" : {
  85.                    "type" : "string",
  86.                    "index": "not_analyzed"
  87.                },
  88.                "speed" : {
  89.                    "type" : "double"
  90.                }
  91.            }
  92.        }
  93.    }
  94. }'
  95. printf "\n"
  96.  
  97. printf "Creating '${AGENDA_EVENT_INDEX}' index mappings...\n"
  98. curl -XDELETE http://${HOST}:${PORT}/${AGENDA_EVENT_INDEX}
  99. curl -XPUT http://${HOST}:${PORT}/${AGENDA_EVENT_INDEX} -d '
  100. {
  101.    "mappings" : {
  102.        "agenda-event" : {
  103.            "properties" : {
  104.                "timestamp": {
  105.                    "type":   "date",
  106.                    "format": "epoch_millis"
  107.                },
  108.                "eventType" : {
  109.                    "type" : "string",
  110.                    "index": "not_analyzed"
  111.                },
  112.                "ruleName" : {
  113.                    "type" : "string"
  114.                },
  115.                "message": {
  116.                    "type":"string"
  117.                },
  118.                "sensor" : {
  119.                    "type" : "string",
  120.                    "index": "not_analyzed"
  121.                },
  122.                "speed" : {
  123.                    "type" : "double"
  124.                }
  125.            }
  126.        }
  127.    }
  128. }'
  129. printf "\n"
  130. printf "Done!\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement