-
-
Save paweloque/9d3a0fe378186eed93593405f3d56758 to your computer and use it in GitHub Desktop.
Elasticsearch's search_as_you_type and completion suggester fields in action
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 jobs | |
{ | |
"mappings": { | |
"properties": { | |
"title": { | |
"type": "search_as_you_type" | |
} | |
} | |
} | |
} | |
POST jobs/_analyze | |
{ | |
"field": "title", | |
"text": [ | |
"Senior Software Developer" | |
] | |
} | |
POST jobs/_analyze | |
{ | |
"field": "title._2gram", | |
"text": [ | |
"Senior Software Developer" | |
] | |
} | |
POST jobs/_analyze | |
{ | |
"field": "title._3gram", | |
"text": [ | |
"Senior Software Developer" | |
] | |
} | |
POST jobs/_analyze | |
{ | |
"field": "title._index_prefix", | |
"text": [ | |
"Senior Software Developer" | |
] | |
} | |
PUT jobs/_bulk?refresh | |
{ "index" : {} } | |
{ "title" : "Software Developer" } | |
{ "index" : {} } | |
{ "title" : "Senior Software Developer" } | |
{ "index" : {} } | |
{ "title" : "Principal Sofware Developer" } | |
{ "index" : {} } | |
{ "title" : "Developer Advocate" } | |
{ "index" : {} } | |
{ "title" : "Developer 🥑" } | |
GET jobs/_search | |
{ | |
"query": { | |
"match_phrase_prefix": { "title": "developer" } | |
} | |
} | |
GET jobs/_search | |
{ | |
"query": { | |
"match_phrase_prefix": { "title": "software dev" } | |
} | |
} | |
GET jobs/_search | |
{ | |
"query": { | |
"match_phrase_prefix": { "title": "senior dev" } | |
} | |
} | |
GET jobs/_search | |
{ | |
"query": { | |
"multi_match": { | |
"query": "senior dev", | |
"type": "bool_prefix", | |
"operator": "and", | |
"fields": [ | |
"title", | |
"title._2gram", | |
"title._3gram" | |
] | |
} | |
} | |
} | |
GET jobs/_search | |
{ | |
"query": { | |
"multi_match": { | |
"query": "senior dev", | |
"type": "bool_prefix", | |
"operator": "or", | |
"fields": [ | |
"title", | |
"title._2gram", | |
"title._3gram" | |
] | |
} | |
} | |
} | |
GET jobs/_search | |
{ | |
"query": { | |
"multi_match": { | |
"query": "🥑", | |
"type": "bool_prefix", | |
"operator": "and", | |
"fields": [ | |
"title", | |
"title._2gram", | |
"title._3gram" | |
] | |
} | |
} | |
} | |
DELETE jobs | |
PUT jobs_completion | |
{ | |
"mappings": { | |
"properties": { | |
"title": { | |
"type": "completion" | |
} | |
} | |
} | |
} | |
PUT jobs_completion/_bulk?refresh | |
{ "index" : {} } | |
{ "title" : "Software Developer" } | |
{ "index" : {} } | |
{ "title" : "Senior Software Developer" } | |
{ "index" : {} } | |
{ "title" : "Principal Sofware Developer" } | |
{ "index" : {} } | |
{ "title" : "Developer Advocate" } | |
{ "index" : {} } | |
{ "title" : "Developer 🥑" } | |
GET jobs_completion/_search | |
{ | |
"suggest": { | |
"job-title": { | |
"prefix": "software dev", | |
"completion": { | |
"field": "title" | |
} | |
} | |
} | |
} | |
GET jobs_completion/_search | |
{ | |
"suggest": { | |
"job-title": { | |
"prefix": "senior dev", | |
"completion": { | |
"field": "title" | |
} | |
} | |
} | |
} | |
DELETE jobs_completion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment