Skip to content

Instantly share code, notes, and snippets.

@p5f8
Created May 1, 2018 15:59
Show Gist options
  • Save p5f8/fc81d23bf91ee9187e2cd47febf7271b to your computer and use it in GitHub Desktop.
Save p5f8/fc81d23bf91ee9187e2cd47febf7271b to your computer and use it in GitHub Desktop.
# https://www.elastic.co/videos/using-the-completion-suggester
# https://stackoverflow.com/questions/28268418/elasticsearch-completion-suggester-on-multifield-with-different-weighting
# ALL tests using elasticsearch 6.2.4 and kibana 6.2.4
DELETE /newclient
PUT /newclient
{
"mappings": {
"_doc" : {
"properties": {
"name" : {
"type": "text"
},
"name_suggest" : {
"type": "completion"
}
}
}
}
}
GET newclient/_doc/_search
# using fuzzy
POST /newproduct/_search
{
"suggest": {
"product_suggestion": {
"text": "ipone",
"completion": {
"field": "name_suggest",
"fuzzy" : {
"fuzziness": 1
}
}
}
}
}
PUT /newclient/_doc/1
{
"name": "Pablo Fernando da Silva",
"name_suggest": {
"input": [
"Pablo Fernando da Silva",
"Pablo Fernando",
"Pablo"
]
},
"output": "Pablo Fernando da Silva"
}
PUT /newclient/_doc/2
{
"name": "Páblo Fernando da Silva",
"name_suggest": {
"input": [
"Páblo Fernando da Silva",
"Páblo Fernando",
"Páblo",
"Pablo"
]
},
"output": "Páblo Fernando da Silva"
}
PUT /newclient/_doc/3
{
"name": "Almerita Maria da Silva",
"name_suggest": {
"input": [
"Almerita Maria da Silva",
"Almerita Maria",
"Almerita"
]
},
"output": "Almerita Maria da Silva"
}
PUT /newclient/_doc/4
{
"name": "Álmerita Maria da Silva",
"name_suggest": {
"input": [
"Álmerita Maria da Silva",
"Álmerita Maria",
"Álmerita",
"Almerita"
]
},
"output": "Álmerita Maria da Silva"
}
PUT /newclient/_doc/5
{
"name": "Pabllo Vittar",
"name_suggest": {
"input": [
"Pabllo Vittar",
"Pabllo",
"Pablo",
"Vitar",
"Vittar"
]
},
"output": "Pabllo Vittar"
}
# great results
POST /newclient/_search
{
"suggest": {
"product_suggestion": {
"text": "pa",
"completion": {
"field": "name_suggest"
}
}
}
}
# using fuzzy
POST /newclient/_search
{
"suggest": {
"product_suggestion": {
"text": "pa",
"completion": {
"field": "name_suggest",
"fuzzy" : {
"fuzziness": 1
}
}
}
}
}
# using fuzzy
POST /newproduct/_search
{
"suggest": {
"product_suggestion": {
"text": "ipxon",
"completion": {
"field": "name_suggest",
"fuzzy" : {
"fuzziness": 2
}
}
}
}
}
# using fuzzy
POST /newclient/_search
{
"suggest": {
"product_suggestion": {
"text": "p",
"completion": {
"field": "name_suggest",
"fuzzy" : {
"fuzziness": 2
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment