如何在Elasticsearch中仅向前创建ngram? [英] How to create ngrams in only forward direction in Elasticsearch?
本文介绍了如何在Elasticsearch中仅向前创建ngram?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以像这样创建ngram:
Is it possible to create the ngrams like this :
homework -> ho,hom,home,homew,homewo,homewor,homework only ?
仅向前方向?
目前,它正在创建所有可能的方式.
Currently its creating all possible ways.
推荐答案
edge_ngram令牌生成器首先将文本分解为单词遇到指定字符列表之一,然后发出每个单词的N-gram,其中N-gram的开头固定在单词的开头.
The edge_ngram tokenizer first breaks text down into words whenever it encounters one of a list of specified characters, then it emits N-grams of each word where the start of the N-gram is anchored to the beginning of the word.
请参阅此官方文档详细了解Edge n-grams
Refer to this official documentation to get a detailed explanation on Edge n-grams
索引映射:
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 10,
"token_chars": [
"letter",
"digit"
]
}
}
}
}
}
分析API
将生成以下令牌:
{
"analyzer": "my_analyzer",
"text": "Homework"
}
tokens": [
{
"token": "Ho",
"start_offset": 0,
"end_offset": 2,
"type": "word",
"position": 0
},
{
"token": "Hom",
"start_offset": 0,
"end_offset": 3,
"type": "word",
"position": 1
},
{
"token": "Home",
"start_offset": 0,
"end_offset": 4,
"type": "word",
"position": 2
},
{
"token": "Homew",
"start_offset": 0,
"end_offset": 5,
"type": "word",
"position": 3
},
{
"token": "Homewo",
"start_offset": 0,
"end_offset": 6,
"type": "word",
"position": 4
},
{
"token": "Homewor",
"start_offset": 0,
"end_offset": 7,
"type": "word",
"position": 5
},
{
"token": "Homework",
"start_offset": 0,
"end_offset": 8,
"type": "word",
"position": 6
}
]
}
这篇关于如何在Elasticsearch中仅向前创建ngram?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文