Created
July 24, 2014 17:02
-
-
Save jprante/7a1763c7073f2b8084a6 to your computer and use it in GitHub Desktop.
Top-hits aggregation demo for Elasticsearch 1.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XDELETE "http://localhost:9200/test" | |
curl -XPUT "http://localhost:9200/test" -d '{ | |
"mappings" : { | |
"employees" : { | |
"properties" : { | |
"fullName" : { | |
"type" : "string", | |
"fields" : { | |
"raw" : { "type": "string", "index": "not_analyzed" } | |
} | |
} | |
} | |
} | |
} | |
}' | |
curl -XPUT "http://localhost:9200/test/employees/1" -d' | |
{ | |
"num" : 1, | |
"fullName": "Don White", | |
"specialty": "Adult Retrovirology, aids, hiv" | |
}' | |
curl -XPUT "http://localhost:9200/test/employees/2" -d' | |
{ | |
"num" : 2, | |
"fullName": "Don White", | |
"specialty": "general practitioner, physician, general, primary care" | |
}' | |
curl -XPUT "http://localhost:9200/test/employees/3" -d' | |
{ | |
"num" : 3, | |
"fullName": "Don White", | |
"specialty": "icu, er" | |
}' | |
curl -XPUT "http://localhost:9200/test/employees/4" -d' | |
{ | |
"num" : 4, | |
"fullName": "Terrance Gartner", | |
"specialty": "oncology, cancer, research, tumor, polyp" | |
}' | |
curl -XPUT "http://localhost:9200/test/employees/5" -d' | |
{ | |
"num" : 5, | |
"fullName": "Terrance Gartner", | |
"specialty": "physician, general, GP, primary care, aids" | |
}' | |
curl -XPUT "http://localhost:9200/test/employees/6" -d' | |
{ | |
"num" : 6, | |
"fullName": "Terrance Gartner", | |
"specialty": "emergency care, icu, ambulance, er, urgent" | |
}' | |
curl -XPUT "http://localhost:9200/test/employees/7" -d' | |
{ | |
"num" : 7, | |
"fullName": "Carter Taylor", | |
"specialty": "neurosurgery, brain surgery, brain tumor" | |
}' | |
curl -XPUT "http://localhost:9200/test/employees/8" -d' | |
{ | |
"num" : 8, | |
"fullName": "Carter Taylor", | |
"specialty": "trauma, icu, emergency care, ER, urgent care" | |
}' | |
curl -XGET 'http://localhost:9200/test/_refresh' | |
curl -XGET "http://localhost:9200/test/employees/_search?pretty=true" -d' | |
{ | |
"query": { | |
"match": { | |
"_all" : "icu" | |
} | |
}, | |
"aggs": { | |
"names": { | |
"terms": { | |
"field": "fullName.raw" | |
}, | |
"aggs": { | |
"top_tags_hits": { | |
"top_hits": { | |
} | |
}, | |
"top_hit": { | |
"max": { | |
"lang" : "expression", | |
"script": "_score" | |
} | |
} | |
} | |
} | |
} | |
}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment