Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexisylchan/3debd1cd38f1755346bc7b93c7b21a5c to your computer and use it in GitHub Desktop.
Save alexisylchan/3debd1cd38f1755346bc7b93c7b21a5c to your computer and use it in GitHub Desktop.
References:
https://qbox.io/blog/tutorial-search-plurals-analyzers-elasticsearch
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/analysis-lang-analyzer.html
https://stackoverflow.com/questions/24257747/normalize-british-and-american-english-for-elasticsearch
https://www.elastic.co/guide/en/elasticsearch/reference/6.1/analysis-mapping-charfilter.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html
curl -X PUT "localhost:9200/recipes" -H 'Content-Type: application/json' -d'
{
"settings": {
"analysis": {
"char_filter": {
"en_char_filter": { "type": "mapping", "mappings": ["aerie=>axerie", "aeroplane=>airplane", "aloe=>aloxe", "canoe=>canoxe", "coerce=>coxerce", "poem=>poxem", "prise=>prixse","armour=>armor", "behaviour=>behavior", "centre=>center", "colour=>color", "clamour=>clamor", "draught=>draft", "endeavour=>endeavor", "favour=>favor", "flavour=>flavor", "harbour=>harbor", "honour=>honor","humour=>humor", "labour=>labor", "litre=>liter", "metre=>meter", "mould=>mold", "neighbour=>neighbor", "plough=>plow", "saviour=>savior", "savour=>savor","ae=>e", "ction=>xion", "disc=>disk", "gramme=>gram", "isable=>izable", "isation=>ization", "ise=>ize", "ising=>izing", "ll=>l", "oe=>e", "ogue=>og", "sation=>zation", "yse=>yze", "ysing=>yzing"] }
},
"filter": {
"english_stop": {
"type": "stop",
"stopwords": "_english_"
},
"english_keywords": {
"type": "keyword_marker",
"keywords": ["example"]
},
"english_stemmer": {
"type": "stemmer",
"language": "english"
},
"english_possessive_stemmer": {
"type": "stemmer",
"language": "possessive_english"
},
"english_synonym_stemmer": {
"type": "synonym",
"synonyms": ["grey=>gray", "greyness=>grayness"]
}
},
"analyzer": {
"english": {
"tokenizer": "standard",
"char_filter": ["en_char_filter"],
"filter": [
"english_possessive_stemmer",
"lowercase",
"english_stop",
"english_keywords",
"english_stemmer",
"english_synonym_stemmer"
]
}
}
}
},
"mappings": {
"recipe": {
"properties": {
"title": {
"type": "text",
"analyzer": "english",
"search_analyzer": "english"
},
"ingredients": {
"type": "text",
"analyzer": "english",
"search_analyzer": "english"
},
"categories": {
"type": "text",
"analyzer": "english",
"search_analyzer": "english"
},
"description": {
"type": "text",
"analyzer": "english",
"search_analyzer": "english"
}
}
}
}
}'
curl -XPUT 'localhost:9200/recipes/recipe/1?pretty' -d '{
"title" :"Fresh Orange Pie",
"ingredients" : "pastry dough, navel orange, sugar, vanilla, coconut",
"description" : "Meanwhile, peel orange and section into segments...",
"categories" : ["pie", "orange"]
}' -H 'Content-Type: application/json'
curl -XPUT 'localhost:9200/recipes/recipe/2?pretty' -d '{
"title" :"Perfect Apple Pie",
"ingredients" : "refrigerated pie crusts, apple, sugar, all-purpose flour, cinnamon, salt, lemon juice",
"description" : "Heat oven to 425°F. Place 1 pie crust in ungreased 9-inch glass pie plate. Press firmly against side and bottom...",
"categories" : ["pie", "apple"]
}' -H 'Content-Type: application/json'
curl -XPUT 'localhost:9200/recipes/recipe/3?pretty' -d '{
"title" : "Apples Jam",
"ingredients" : "apples, sugar, vanilla",
"description" : "Bring sugar and 3 Tbsp. water to a boil in a large pot over medium-high heat, stirring to dissolve sugar….",
"categories" : ["jam", "apples"]
}' -H 'Content-Type: application/json'
curl -XPUT 'localhost:9200/recipes/recipe/3?pretty' -d '{
"title" : "Apples Jam",
"ingredients" : "apples, sugar, vanilla",
"description" : "Bring sugar grey and 3 Tbsp. water to a boil in a large pot over medium-high heat, stirring to dissolve sugar….",
"categories" : ["jam", "apples"]
}' -H 'Content-Type: application/json'
curl -XGET 'localhost:9200/recipes/_search?q=oranges'
curl -XGET 'localhost:9200/recipes/_search?q=gray'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment