Skip to content

Instantly share code, notes, and snippets.

@joshuar
Created May 31, 2017 23:20
Show Gist options
  • Save joshuar/d93eaeae8d2ffefb6b2e50a52a8508e3 to your computer and use it in GitHub Desktop.
Save joshuar/d93eaeae8d2ffefb6b2e50a52a8508e3 to your computer and use it in GitHub Desktop.
Performing a suffix search
PUT test
{
"settings": {
"analysis": {
"analyzer": {
"ReverseIt": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"reverse"
]
}
}
}
},
"mappings": {
"t": {
"properties": {
"MyField": {
"type": "text",
"fields": {
"Reversed": {
"type": "text",
"analyzer": "ReverseIt"
}
}
}
}
}
}
}
PUT test/_bulk
{ "index" : { "_index" : "test", "_type" : "t" } }
{ "MyField": "foo bar" }
{ "index" : { "_index" : "test", "_type" : "t" } }
{ "MyField": "foo mint" }
{ "index" : { "_index" : "test", "_type" : "t" } }
{ "MyField": "foo please" }
GET test/t/_search
{
"query": {
"match_phrase_prefix": {
"MyField.Reversed": "bar"
}
}
}
# Results in:
{
"took": 27,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.2876821,
"hits": [
{
"_index": "test",
"_type": "t",
"_id": "AVxgzR9hj1WMFjDCaZvs",
"_score": 0.2876821,
"_source": {
"MyField": "foo bar"
}
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment