Skip to content

Instantly share code, notes, and snippets.

@danyim
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danyim/384d88ee0015009033d7 to your computer and use it in GitHub Desktop.
Save danyim/384d88ee0015009033d7 to your computer and use it in GitHub Desktop.
Using the top_hits aggregator
curl -XDELETE "http://localhost:9200/personsearch"
curl -XPUT "http://localhost:9200/personsearch" -d'
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"idx_analyzer": {
"tokenizer": "CommaTokenizer",
"filter": [
"lowercase",
"trim",
"snowball",
"stop",
"XYZSynFilter"
]
},
"sch_analyzer": {
"tokenizer": "standard",
"filter": [
"lowercase",
"trim",
"snowball",
"stop"
]
},
"sch_comma_analyzer": {
"tokenizer": "CommaTokenizer",
"filter": [
"standard",
"lowercase",
"trim",
"stop"
]
}
},
"filter": {
"XYZSynFilter": {
"type": "synonym",
"synonyms": [
"aids virus, aids, retrovirology, hiv"
],
"expand": true,
"ignore_case": true
}
},
"tokenizer": {
"CommaTokenizer": {
"type": "pattern",
"pattern": ","
}
}
}
}
},
"mappings": {
"employees": {
"properties": {
"fullName": {
"type": "string",
"index_analyzer": "idx_analyzer",
"search_analyzer": "sch_analyzer"
},
"specialty": {
"type": "string",
"index_analyzer": "idx_analyzer",
"search_analyzer": "sch_analyzer"
}
}
}
}
}'
curl -XPUT "http://localhost:9200/personsearch/employees/1" -d'
{
"fullName": "Don White",
"specialty": "Adult Retrovirology, aids, hiv"
}'
curl -XPUT "http://localhost:9200/personsearch/employees/2" -d'
{
"fullName": "Don White",
"specialty": "general practitioner, physician, general, primary care"
}'
curl -XPUT "http://localhost:9200/personsearch/employees/3" -d'
{
"fullName": "Don White",
"specialty": "icu, er"
}'
curl -XPUT "http://localhost:9200/personsearch/employees/4" -d'
{
"fullName": "Terrance Gartner",
"specialty": "oncology, cancer, research, tumor, polyp, icu"
}'
curl -XPUT "http://localhost:9200/personsearch/employees/5" -d'
{
"fullName": "Terrance Gartner",
"specialty": "physician, general, GP, primary care, aids, icu"
}'
curl -XPUT "http://localhost:9200/personsearch/employees/6" -d'
{
"fullName": "Terrance Gartner",
"specialty": "emergency care, icu, ambulance, er, urgent"
}'
curl -XPUT "http://localhost:9200/personsearch/employees/7" -d'
{
"fullName": "Carter Taylor",
"specialty": "neurosurgery, brain surgery, brain tumor"
}'
curl -XPUT "http://localhost:9200/personsearch/employees/8" -d'
{
"fullName": "Carter Taylor",
"specialty": "trauma, icu, emergency care, ER, urgent care"
}'
curl -XGET "http://localhost:9200/personsearch/employees/_search?pretty=true" -d'
{
"query": {
"match": {
"_all": "icu"
}
},
"aggs": {
"most-rel-agg": {
"terms": {
"field": "fullName",
"order": {
"top_hit": "desc"
}
},
"aggs": {
"most-rel-profile": {
"top_hits": {}
},
"top_hit": {
"max": {
"script": "_doc.score"
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment