Last active
August 29, 2015 14:04
Using the top_hits aggregator
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/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