Skip to content

Instantly share code, notes, and snippets.

@djptek
Created December 14, 2018 14:12
Show Gist options
  • Save djptek/b055cd2f1cd97b7ba440ac975c1efac0 to your computer and use it in GitHub Desktop.
Save djptek/b055cd2f1cd97b7ba440ac975c1efac0 to your computer and use it in GitHub Desktop.
2019 Fiestas Nacionales/Comunidad Indexed to Elasticsearch
# up to the eggs trying to figure out when fiestas are next year?
# For 2019 I dumped the fiestas into Json, incuding:
# - Fiesta Nacional no sustituible
# - Fiesta Nacional respecto de la que no se ha ejercido la facultad de sustitución
# - Fiesta de Comunidad Autónoma
# Source: https://www.ccoo-servicios.es/archivos/anexo-BOE.pdf
# please check vs PDF in case of error & remember to add any city/local fiestas
# and then I indexed it in Elasticsearch
# de-dupe by fiesta name as dates may be repeated
PUT _ingest/pipeline/fiesta_to_id
{
"description": "set _id to fiesta",
"processors": [
{
"script": {
"source": "ctx._id = ctx.fiesta;"
}
}
]
}
# mapping, always
PUT fiestas_vs_comunidad_autonoma
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"_doc": {
"properties": {
"comunidades": {
"type": "keyword"
},
"date": {
"type": "date"
},
"fiesta": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
# _bulk load the data
POST fiestas_vs_comunidad_autonoma/_doc/_bulk
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-01-01", "fiesta": "Año Nuevo", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","ILLES BALEARS","CANARIAS","CANTABRIA","CASTILLA-LA MANCHA","CASTILLA Y LEÓN","CATALUÑA","COMUNITAT VALENCIANA","EXTREMADURA","GALICIA","MADRID","MURCIA","NAVARRA","PAÍS VASCO","LA RIOJA","CIUDAD DE CEUTA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-01-07", "fiesta": "Lunes siguiente a Epifanía", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","CANARIAS","CASTILLA Y LEÓN","EXTREMADURA","MADRID","MURCIA","NAVARRA","CIUDAD DE CEUTA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-02-28", "fiesta": "Día de Andalucía", "comunidades": ["ANDALUCÍA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-03-01", "fiesta": "Día de las Illes Balears", "comunidades": ["ILLES BALEARS"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-03-19", "fiesta": "San José", "comunidades": ["COMUNITAT VALENCIANA","GALICIA","MURCIA","NAVARRA","PAÍS VASCO"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-04-18", "fiesta": "Jueves Santo", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","ILLES BALEARS","CANARIAS","CANTABRIA","CASTILLA-LA MANCHA","CASTILLA Y LEÓN","EXTREMADURA","GALICIA","MADRID","MURCIA","NAVARRA","PAÍS VASCO","LA RIOJA","CIUDAD DE CEUTA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-04-19", "fiesta": "Viernes Santo", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","ILLES BALEARS","CANARIAS","CANTABRIA","CASTILLA-LA MANCHA","CASTILLA Y LEÓN","CATALUÑA","COMUNITAT VALENCIANA","EXTREMADURA","GALICIA","MADRID","MURCIA","NAVARRA","PAÍS VASCO","LA RIOJA","CIUDAD DE CEUTA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-04-22", "fiesta": "Lunes de Pascua", "comunidades": ["ILLES BALEARS","CANTABRIA","CASTILLA-LA MANCHA","CATALUÑA","COMUNITAT VALENCIANA","NAVARRA","PAÍS VASCO","LA RIOJA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-04-23", "fiesta": "San Jorge / Día de Aragón", "comunidades": ["ARAGÓN"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-04-23", "fiesta": "Fiesta Castilla y León", "comunidades": ["CASTILLA Y LEÓN"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-05-01", "fiesta": "Fiesta del Trabajo", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","ILLES BALEARS","CANARIAS","CANTABRIA","CASTILLA-LA MANCHA","CASTILLA Y LEÓN","CATALUÑA","COMUNITAT VALENCIANA","EXTREMADURA","GALICIA","MADRID","MURCIA","NAVARRA","PAÍS VASCO","LA RIOJA","CIUDAD DE CEUTA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-05-02", "fiesta": "Día de la Comunidad de Madrid", "comunidades": ["MADRID"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-05-17", "fiesta": "Día de las Letras Gallegas", "comunidades": ["GALICIA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-05-30", "fiesta": "Día de Canarias", "comunidades": ["CANARIAS"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-05-31", "fiesta": "Día de Castilla-La Mancha", "comunidades": ["CASTILLA-LA MANCHA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-06-10", "fiesta": "Día de la Región de Murcia", "comunidades": ["MURCIA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-06-10", "fiesta": "Día de La Rioja", "comunidades": ["LA RIOJA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-06-20", "fiesta": "Corpus Christi", "comunidades": ["CASTILLA-LA MANCHA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-06-24", "fiesta": "San Juan", "comunidades": ["CATALUÑA","COMUNITAT VALENCIANA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-07-25", "fiesta": "Santiago Apóstol / Día Nacional de Galicia", "comunidades": ["CANTABRIA","GALICIA","PAÍS VASCO"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-08-12", "fiesta": "Fiesta del Sacrificio - Eidul Adha", "comunidades": ["CIUDAD DE CEUTA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-08-12", "fiesta": "Fiesta del Sacrificio (Aid El Kebir)", "comunidades": ["CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-08-15", "fiesta": "Asunción de la Virgen", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","ILLES BALEARS","CANARIAS","CANTABRIA","CASTILLA-LA MANCHA","CASTILLA Y LEÓN","CATALUÑA","COMUNITAT VALENCIANA", "EXTREMADURA","GALICIA","MADRID","MURCIA","NAVARRA","PAÍS VASCO","LA RIOJA","CIUDAD DE CEUTA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-09-02", "fiesta": "Día de Ceuta", "comunidades": ["CIUDAD DE CEUTA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-09-09", "fiesta": "Lunes siguiente al Día de Asturias", "comunidades": ["ASTURIAS"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-09-09", "fiesta": "Lunes siguiente al Día de Extremadura", "comunidades": ["EXTREMADURA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-09-11", "fiesta": "Fiesta Nacional de Cataluña", "comunidades": ["CATALUÑA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-10-09", "fiesta": "Día de la Comunitat Valenciana", "comunidades": ["COMUNITAT VALENCIANA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-10-12", "fiesta": "Fiesta Nacional de España", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","ILLES BALEARS","CANARIAS","CANTABRIA","CASTILLA-LA MANCHA","CASTILLA Y LEÓN","CATALUÑA","COMUNITAT VALENCIANA", "EXTREMADURA","GALICIA","MADRID","MURCIA","NAVARRA","PAÍS VASCO","LA RIOJA","CIUDAD DE CEUTA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-11-01", "fiesta": "Todos los Santos", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","ILLES BALEARS","CANARIAS","CANTABRIA","CASTILLA-LA MANCHA","CASTILLA Y LEÓN","CATALUÑA","COMUNITAT VALENCIANA","EXTREMADURA","GALICIA","MADRID","MURCIA","NAVARRA","PAÍS VASCO","LA RIOJA","CIUDAD DE CEUTA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-12-06", "fiesta": "Día de la Constitución Española", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","ILLES BALEARS","CANARIAS","CANTABRIA","CASTILLA-LA MANCHA","CASTILLA Y LEÓN","CATALUÑA","COMUNITAT VALENCIANA","EXTREMADURA","GALICIA","MADRID","MURCIA","NAVARRA","PAÍS VASCO","LA RIOJA","CIUDAD DE CEUTA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-12-09", "fiesta": "Lunes siguiente a la Inmaculada Concepción", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","CANTABRIA","CASTILLA Y LEÓN","EXTREMADURA","MADRID","LA RIOJA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-12-25", "fiesta": "Natividad del Señor", "comunidades": ["ANDALUCÍA","ARAGÓN","ASTURIAS","ILLES BALEARS","CANARIAS","CANTABRIA","CASTILLA-LA MANCHA","CASTILLA Y LEÓN","CATALUÑA","COMUNITAT VALENCIANA","EXTREMADURA","GALICIA","MADRID","MURCIA","NAVARRA","PAÍS VASCO","LA RIOJA","CIUDAD DE CEUTA","CIUDAD DE MELILLA"]}
{"index": {"pipeline": "fiesta_to_id"}}
{"date": "2019-12-26", "fiesta": "San Esteban", "comunidades": ["ILLES BALEARS","CATALUÑA"]}
# Now let's ask some questions
# How many days in the year have a fiesta (somewhere)?
# (some days have more than one fiesta)
GET fiestas_vs_comunidad_autonoma/_search
{
"size": 0,
"aggs": {
"count_dates": {
"cardinality": {
"field": "date"
}
}
}
}
}
# Fiesta Count by Community
GET fiestas_vs_comunidad_autonoma/_search
{
"size": 0,
"aggs": {
"check_comunidades": {
"terms": {
"field": "comunidades",
"size": 19,
"order": {
"_key": "asc"
}
}
}
}
}
# All Fiestas foreach Community
# This could have gone in the pipeline
# Note: hard-coding 19 is _not_ a political statement on my part,
# it's just the numnber of columns in the source data.
# If that worries you use a composite aggregation
GET fiestas_vs_comunidad_autonoma/_search?filter_path=**.key
{
"size": 0,
"aggs": {
"my_comunidades": {
"terms": {
"field": "comunidades",
"size": 19,
"order": {
"_key": "asc"
}
},
"aggs": {
"my_local_fiesta": {
"terms": {
"script": {
"source": "doc['date'].value.toString('yyyy/MM/dd')+' - '+doc['fiesta.keyword'].value"
},
"size": 14
}
}
}
}
}
}
# When is San José?
GET fiestas_vs_comunidad_autonoma/_search?filter_path=**.date
{
"query": {
"match_phrase": {
"fiesta": "San José"
}
}
}
# Which Community celebrates San José?
GET fiestas_vs_comunidad_autonoma/_search?filter_path=**.comunidades
{
"query": {
"match_phrase": {
"fiesta": "San José"
}
}
}
# How many days are Fiestas when Madrid doesn't have a fiesta?
GET fiestas_vs_comunidad_autonoma/_search
{
"size": 0,
"query": {
"bool": {
"must_not": [
{"match": {
"comunidades": "MADRID"
}}
]
}
},
"aggs": {
"remove_duplicate_dates": {
"cardinality": {
"field": "date"
}
}
}
}
# memo to self: now I need some Kibana region maps...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment