Created
December 18, 2017 16:14
-
-
Save astefan/f3e8f9ff870c5efed860588186af7e14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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