Skip to content

Instantly share code, notes, and snippets.

@jtreher
Last active December 17, 2015 08:08
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 jtreher/5577747 to your computer and use it in GitHub Desktop.
Save jtreher/5577747 to your computer and use it in GitHub Desktop.
Demonstrate suggest issue
curl -XPOST 192.168.1.2:9200/test -d'{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"filter":{
"shingler":{
"type":"shingle",
"max_shingle_size":3,
"min_shingle_sizes":2
}
},
"analyzer":{
"biword": {
"filter": [
"lowercase",
"asciifolding",
"shingler"
],
"type": "custom",
"tokenizer": "standard"
}
}
}
},
"mappings": {
"docs": {
"properties": {
"name": {
"type": "multi_field",
"path":"just_name",
"fields":{
"name":{
"type":"string"
},
"name_shingled":{
"index_analyzer":"biword",
"search_analyzer":"standard",
"type":"string"
}
}
}
}
}
}
}'
//we are going to test for a bad phrase "ice tea." We want "iced tea" as a suggest.
curl -XPOST 192.168.1.2:9200/test/docs/ -d '{"name":"I like iced tea."}'
curl -XPOST 192.168.1.2:9200/test/docs/ -d '{"name":"I like tea."}'
curl -XPOST 192.168.1.2:9200/test/docs/ -d '{"name":"I like ice cream."}'
//test the phrase "ice tea" No results. "icer tea" will work.
curl -XPOST 192.168.1.2:9200/test/_suggest -d '{
"text": "ice tea",
"did_you_mean": {
"phrase": {
"field": "name_shingled",
"gram_size": 3,
"direct_generator": [
{
"field": "name",
"max_edits": 2,
"suggest_mode": "always",
"min_word_len": 0,
"prefix_len": 0
}
]
}
}
}'
//try out our direct generator...iced is a recommended term and should be part of the candiates
curl -XPOST 192.168.1.2:9200/test/_suggest -d'{
"did_you_mean": {
"text": "ice",
"term": {
"field": "name",
"max_edits":2,
"suggest_mode": "always",
"min_word_len": 0,
"prefix_len": 0
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment