Skip to content

Instantly share code, notes, and snippets.

@cinhtau
Last active February 20, 2019 11:08
Show Gist options
  • Save cinhtau/491f449a37918e84dd27ae652e3e4ce9 to your computer and use it in GitHub Desktop.
Save cinhtau/491f449a37918e84dd27ae652e3e4ce9 to your computer and use it in GitHub Desktop.
Voting Example

Data from vote 626

Remove type for ES 7.

POST _bulk
{"index":{"_index":"votes","_type":"doc","_id":"1"}}
{"canton":"Zürich","votes":{"yes":148438,"no":222301},"participation":40.2}
{"index":{"_index":"votes","_type":"doc","_id":"2"}}
{"canton":"Bern","votes":{"yes":96671,"no":179706},"participation":37.8}
{"index":{"_index":"votes","_type":"doc","_id":"3"}}
{"canton":"Luzern","votes":{"yes":34375,"no":67599},"participation":37.1}
{"index":{"_index":"votes","_type":"doc","_id":"4"}}
{"canton":"Uri","votes":{"yes":2645,"no":6099},"participation":33.3}
{"index":{"_index":"votes","_type":"doc","_id":"5"}}
{"canton":"Schwyz","votes":{"yes":10909,"no":30758},"participation":39.7}
{"index":{"_index":"votes","_type":"doc","_id":"6"}}
{"canton":"Obwalden","votes":{"yes":2494,"no":7811},"participation":39.2}
{"index":{"_index":"votes","_type":"doc","_id":"7"}}
{"canton":"Nidwalden","votes":{"yes":2846,"no":8863},"participation":37.6}
{"index":{"_index":"votes","_type":"doc","_id":"8"}}
{"canton":"Glarus","votes":{"yes":2617,"no":4626},"participation":27.5}
{"index":{"_index":"votes","_type":"doc","_id":"9"}}
{"canton":"Zug","votes":{"yes":9867,"no":22484},"participation":42}
{"index":{"_index":"votes","_type":"doc","_id":"10"}}
{"canton":"Freiburg","votes":{"yes":25726,"no":41932},"participation":33.5}
{"index":{"_index":"votes","_type":"doc","_id":"11"}}
{"canton":"Solothurn","votes":{"yes":22445,"no":39632},"participation":34.7}
{"index":{"_index":"votes","_type":"doc","_id":"12"}}
{"canton":"Basel-Stadt","votes":{"yes":24294,"no":27928},"participation":47.1}
{"index":{"_index":"votes","_type":"doc","_id":"13"}}
{"canton":"Basel-Landschaft","votes":{"yes":25487,"no":44381},"participation":37.7}
{"index":{"_index":"votes","_type":"doc","_id":"14"}}
{"canton":"Schaffhausen","votes":{"yes":12057,"no":17618},"participation":61.4}
{"index":{"_index":"votes","_type":"doc","_id":"15"}}
{"canton":"Appenzell Ausserrhoden","votes":{"yes":5278,"no":9092},"participation":37.1}
{"index":{"_index":"votes","_type":"doc","_id":"16"}}
{"canton":"Appenzell Innerrhoden","votes":{"yes":1108,"no":2838},"participation":33.7}
{"index":{"_index":"votes","_type":"doc","_id":"17"}}
{"canton":"St. Gallen","votes":{"yes":38351,"no":76005},"participation":35.5}
{"index":{"_index":"votes","_type":"doc","_id":"18"}}
{"canton":"Graubünden","votes":{"yes":12529,"no":32114},"participation":32.6}
{"index":{"_index":"votes","_type":"doc","_id":"19"}}
{"canton":"Aargau","votes":{"yes":48506,"no":95775},"participation":34}
{"index":{"_index":"votes","_type":"doc","_id":"20"}}
{"canton":"Thurgau","votes":{"yes":22603,"no":45012},"participation":40}
{"index":{"_index":"votes","_type":"doc","_id":"21"}}
{"canton":"Tessin","votes":{"yes":29275,"no":40774},"participation":32.4}
{"index":{"_index":"votes","_type":"doc","_id":"22"}}
{"canton":"Waadt","votes":{"yes":62237,"no":105597},"participation":38.2}
{"index":{"_index":"votes","_type":"doc","_id":"23"}}
{"canton":"Wallis","votes":{"yes":20286,"no":74813},"participation":43.2}
{"index":{"_index":"votes","_type":"doc","_id":"24"}}
{"canton":"Neuenburg","votes":{"yes":16466,"no":19153},"participation":32.3}
{"index":{"_index":"votes","_type":"doc","_id":"25"}}
{"canton":"Genf","votes":{"yes":53703,"no":58835},"participation":43.8}
{"index":{"_index":"votes","_type":"doc","_id":"26"}}
{"canton":"Jura","votes":{"yes":6057,"no":9718},"participation":29.9}

Delete existing index

DELETE votes

Create Index, ES 7 does not need doc type anymore 😄

PUT votes
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "doc": {
      "properties": {
        "canton": {
          "type": "keyword"
        },
        "votes": {
          "properties": {
            "yes": {
              "type": "long"
            },
            "no": {
              "type": "long"
            },
            "yes-percent": {
              "type": "float"
            },
            "no-percent": {
              "type": "float"
            }
          }
        },
        "participation": {
          "type": "float"
        }
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment