Created
May 31, 2017 23:20
-
-
Save joshuar/d93eaeae8d2ffefb6b2e50a52a8508e3 to your computer and use it in GitHub Desktop.
Performing a suffix search
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
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