Skip to content

Instantly share code, notes, and snippets.

@astefan
Created December 18, 2017 16:14
Show Gist options
  • Save astefan/f3e8f9ff870c5efed860588186af7e14 to your computer and use it in GitHub Desktop.
Save astefan/f3e8f9ff870c5efed860588186af7e14 to your computer and use it in GitHub Desktop.
DELETE test
PUT test
{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
},
"custom_shingle": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 3,
"output_unigrams": true
},
"my_char_filter": {
"type": "pattern_replace",
"pattern": " ",
"replacement": ""
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"custom_shingle",
"autocomplete_filter",
"my_char_filter"
]
}
}
}
},
"mappings": {
"my_type": {
"properties": {
"item_id": {
"type": "string",
"analyzer": "autocomplete",
"search_analyzer": "standard"
},
"item_name": {
"type": "string",
"analyzer": "autocomplete",
"search_analyzer": "standard",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
}
POST /test/my_type/_bulk
{"index":{}}
{"item_id":1,"item_name":"Pin"}
{"index":{}}
{"item_id":2,"item_name":"Mickey Pin"}
{"index":{}}
{"item_id":3,"item_name":"Blue Pin"}
{"index":{}}
{"item_id":4,"item_name":"Cap"}
{"index":{}}
{"item_id":5,"item_name":"Baseball Cap"}
{"index":{}}
{"item_id":6,"item_name":"Red Cap"}
GET test/_search
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"fields": [
"item_name",
"item_id"
],
"query": "Pin",
"fuzziness": "AUTO"
}
},
{
"term": {
"item_name.keyword": {
"value": "Pin"
}
}
}
]
}
},
"highlight": {
"fields": {
"item_name": {},
"item_id": {}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment