Skip to content

Instantly share code, notes, and snippets.

@silentsudo
Created January 15, 2023 06:02
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 silentsudo/073d7ebb4df9ede6e56b57f067b1904f to your computer and use it in GitHub Desktop.
Save silentsudo/073d7ebb4df9ede6e56b57f067b1904f to your computer and use it in GitHub Desktop.
should match search as you type
DELETE products
PUT products
{
"mappings": {
"properties": {
"title": {
"type": "search_as_you_type"
}
}
}
}
GET products/_mapping?pretty
POST products/_doc
{
"title": "best jogging shoes for men"
}
GET products/_search
{
"query": {
"multi_match": {
"query": "st",
"type": "bool_prefix",
"fields": [
"title",
"title._2gram",
"title._3gram"
]
}
}
}
GET products/_search
{
"query": {
"bool": {
"should": [
{
"query_string": {
"default_field": "title",
"query": "*st"
}
},
{
"multi_match": {
"query": "st",
"type": "bool_prefix",
"fields": [
"title",
"title._2gram",
"title._3gram"
]
}
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment