Last active
August 17, 2017 21:49
-
-
Save wshirey/cd1f3faa4505a50b8335ea9b84582c99 to your computer and use it in GitHub Desktop.
elasticsearch ngram analyzer with multifields
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 my_index | |
PUT my_index | |
{ | |
"settings": { | |
"analysis": { | |
"analyzer": { | |
"my_analyzer": { | |
"filter": ["english_stop", "lowercase"], | |
"tokenizer": "my_tokenizer" | |
} | |
}, | |
"filter": { | |
"english_stop": { | |
"type": "stop", | |
"stopwords": [ | |
"_english_" | |
] | |
} | |
}, | |
"tokenizer": { | |
"my_tokenizer": { | |
"type": "ngram", | |
"min_gram": 3, | |
"max_gram": 3, | |
"token_chars": [ | |
"letter", | |
"digit" | |
] | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"my_type": { | |
"properties": { | |
"text": { | |
"type": "text", | |
"fields": { | |
"english": { | |
"type": "text", | |
"analyzer": "english" | |
}, | |
"ngrams": { | |
"type": "text", | |
"analyzer": "my_analyzer" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
POST my_index/_analyze | |
{ | |
"analyzer": "my_analyzer", | |
"text": "The Quick Brown Foxes" | |
} | |
PUT my_index/my_type/1 | |
{ "text": "quick brown fox" } | |
PUT my_index/my_type/2 | |
{ "text": "quick brown foxes" } | |
PUT my_index/my_type/3 | |
{ "text": "some new child care program" } | |
PUT my_index/my_type/4 | |
{ "text": "some other childcare program" } | |
PUT my_index/my_type/5 | |
{ "text": "some other child_care program" } | |
PUT my_index/my_type/ | |
GET my_index/_search | |
{ | |
"query": { | |
"multi_match": { | |
"query": "child care", | |
"fields": [ | |
"text", | |
"text.english", | |
"text.ngrams" | |
], | |
"type": "most_fields", | |
"analyzer": "standard" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try searching for terms