Skip to content

Instantly share code, notes, and snippets.

@akaDPR
Created February 13, 2020 10:36
Show Gist options
  • Save akaDPR/57bde138e1fa673c9b9e2ac91f405782 to your computer and use it in GitHub Desktop.
Save akaDPR/57bde138e1fa673c9b9e2ac91f405782 to your computer and use it in GitHub Desktop.
elastic search - Mapping for search in e-commerce search-boxes
/* Used NodeJS Client for ElasticSearch */
/* ---- A simple mapping for Products and ProductURL ---- */
{
"properties": {
"autocomplete": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "autocomplete_search"
},
"product_url": {
"type": "text"
},
"product_name": {
"type": "text"
}
}
}
/* --- Settings for the above _mapping --- */
{
"settings": {
"analysis": {
"analyzer": {
"autocomplete": {
"tokenizer": "autocomplete",
"filter": [
"lowercase"
]
},
"autocomplete_search": {
"tokenizer": "lowercase"
}
},
"tokenizer": {
"autocomplete": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 20,
"token_chars": [
"letter"
]
}
}
}
}
}
/* --- Sample _doc --- */
{ "product_name": "Everyday Wear Diamond Ring" , "product_url":"https://www.nacjewellers.com/everyday-wear-diamond-ring/2542" }
/* --- sample query for _search API */
{
"query": {
"match": {
"autocomplete": {
"query": <search-text>,
"operator": "and",
"fuzziness": 2
}
}
}
}
/*contact : altruist.curio@gmail.com */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment