Skip to content

Instantly share code, notes, and snippets.

@Mpdreamz
Last active August 29, 2015 14:02
Show Gist options
  • Save Mpdreamz/785a3347d4415e1fe6bb to your computer and use it in GitHub Desktop.
Save Mpdreamz/785a3347d4415e1fe6bb to your computer and use it in GitHub Desktop.
Metadata aggregations example
DELETE /countries
PUT /countries
{
"mappings": {
"anthems" : {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
POST /countries/anthems/1
{
"title": "Ja, vi elsker dette landet",
"lyrics": "Ja, vi elsker dette landet, som det stiger frem, furet, værbitt, over vannet, med de tusen hjem. Elsker, elsker det og tenker på vår far og mor og den saganatt som senker drømmer på vår jord. og den saganatt som senker, senker drømmer på vår jord. Norske mann I hus og hytte, takk din store Gud! Landet ville han beskytte skjønt det mørkt så ut. Alt hva fedrene har kjempet, mødrene har grett, har den Herre stille lempet, så vi vant vår rett. har den Herre stille lempet, så vi vant, vi vant vår rett. Ja, vi elsker dette landet, som det stiger frem, furet, værbitt, over vannet, med de tusen hjem. og som fedres kamp har hevet det av nød til seir, også vi, nar det blir krevet, for dets fred slår leir, også vi, nar det blir krevet, for dets fred, dets fred slår leir!",
"count": 30,
"location": {
"lat": 18.0,
"lon": 2.0
}
}
POST /countries/anthems/usa
{
"title": "The Star Spangled Banner",
"lyrics": "Oh, say! can you see by the dawn's early light What so proudly we hailed at the twilight's last gleaming; Whose broad stripes and bright stars, through the perilous fight, O'er the ramparts we watched were so gallantly streaming? And the rocket's red glare, the bombs bursting in air, Gave proof through the night that our flag was still there: Oh, say! does that star-spangled banner yet wave O'er the land of the free and the home of the brave? On the shore, dimly seen through the mists of the deep, Where the foe's haughty host in dread silence reposes, What is that which the breeze, o'er the towering steep, As it fitfully blows, half conceals, half discloses? Now it catches the gleam of the morning's first beam, In fully glory reflected now shines in the stream: 'Tis the star-spangled banner! Oh, long may it wave O'er the land of the free and the home of the brave! And where is that band who so vauntingly swore That the havoc of war and the battle's confusion A home and a country should leave us no more? Their blood has washed out their foul footsteps' pollution! No refuge could save the hireling and slave From the terror of flight or the gloom of the grave: And the star-spangled banner in triumph doth wave O'er the land of the free and the home of the brave. Oh, thus be it ever, when freemen shall stand Between their loved home and the war's desolation! Blest with victory and peace, may the heav'n-rescued land Praise the Power that hath made and preserved us a nation! Then conquer we must, when our cause it is just, And this be our motto: 'In God is our trust': And the star-spangled banner in triumph shall wave O'er the land of the free and the home of the brave.",
"count": 40,
"location": {
"lat": 28.0,
"lon": 21.0
}
}
POST /countries/anthems/_search?12
{
"size": 0,
"aggs": {
"name": {
"terms": {
"field": "title"
},
"meta": { "number_of_clicks" : 2 },
"aggs": {
"viewport" : {
"meta" : {
"hasColor" : true
},
"geo_bounds" : {
"field" : "location"
}
},
"empty_agg" : {
"meta" : {
"string" : "returns"
},
"sum": {
"field": "i_do_not_exist"
}
},
"nested_terms": {
"terms": {
"field": "lyrics",
"size": 10
},
"meta": {
"complex" : "object",
"number" : 1
},
"aggs": {
"counter": {
"avg": {
"field": "count"
},
"meta": {
"double" : 4.1
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment