English analyzer
The built-in english
analyzer can be applied to a text field using the following command:
PUT /english-index
{
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "english"
}
}
}
}
copy
Stem exclusion
You can use stem_exclusion
with this language analyzer using the following command:
PUT index_with_stem_exclusion_english_analyzer
{
"settings": {
"analysis": {
"analyzer": {
"stem_exclusion_english_analyzer": {
"type": "english",
"stem_exclusion": ["authority", "authorization"]
}
}
}
}
}
copy
English analyzer internals
The english
analyzer is built using the following components:
Tokenizer:
standard
Token filters:
- stemmer (possessive_english)
- lowercase
- stop (English)
- keyword
- stemmer (English)
Custom English analyzer
You can create a custom English analyzer using the following command:
PUT /english-index
{
"settings": {
"analysis": {
"filter": {
"english_stop": {
"type": "stop",
"stopwords": "_english_"
},
"english_stemmer": {
"type": "stemmer",
"language": "english"
},
"english_keywords": {
"type": "keyword_marker",
"keywords": []
},
"english_possessive_stemmer": {
"type": "stemmer",
"language": "possessive_english"
}
},
"analyzer": {
"english_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"english_possessive_stemmer",
"lowercase",
"english_stop",
"english_keywords",
"english_stemmer"
]
}
}
}
},
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "english_analyzer"
}
}
}
}
copy
Generated tokens
Use the following request to examine the tokens generated using the analyzer:
POST /english-index/_analyze
{
"field": "content",
"text": "The students study in the USA and work at NASA. Their numbers are 123456."
}
copy
The response contains the generated tokens:
{
"tokens": [
{"token": "student","start_offset": 4,"end_offset": 12,"type": "<ALPHANUM>","position": 1},
{"token": "studi","start_offset": 13,"end_offset": 18,"type": "<ALPHANUM>","position": 2},
{"token": "usa","start_offset": 26,"end_offset": 29,"type": "<ALPHANUM>","position": 5},
{"token": "work","start_offset": 34,"end_offset": 38,"type": "<ALPHANUM>","position": 7},
{"token": "nasa","start_offset": 42,"end_offset": 46,"type": "<ALPHANUM>","position": 9},
{"token": "number","start_offset": 54,"end_offset": 61,"type": "<ALPHANUM>","position": 11},
{"token": "123456","start_offset": 66,"end_offset": 72,"type": "<NUM>","position": 13}
]
}
当前内容版权归 OpenSearch 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 OpenSearch .