Elasticsearch定制分析器 [英] Elasticsearch custom analyser
本文介绍了Elasticsearch定制分析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以创建可按空间划分索引然后创建两个令牌的自定义Elasticsearch分析器?一是空间前的一切,二是空间。
例如:我存储的记录字段包含以下文本: 35 G。
现在,我想通过仅在该字段中键入 35或 35 G查询来接收该记录。
因此,Elastic应该创建两个令牌:['35','35 G']和更多令牌。
Is it possible to create custom elasticsearch analyser which can split index by space and then create two tokens? One, with everything before space and second, with everything. For example: I have stored record with field which has following text: '35 G'. Now I want to receive that record by typing only '35' or '35 G' query to that field. So elastic should create two tokens: ['35', '35 G'] and no more.
如果可能,如何实现?
推荐答案
可行使用 path_hierarchy
标记生成器。
Doable using path_hierarchy
tokenizer.
PUT test
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "path_hierarchy",
"delimiter": " "
}
}
}
}
...
}
现在
POST test/_analyze
{
"analyzer": "my_analyzer",
"text": "35 G"
}
输出
{
"tokens": [
{
"token": "35",
"start_offset": 0,
"end_offset": 2,
"type": "word",
"position": 0
},
{
"token": "35 G",
"start_offset": 0,
"end_offset": 4,
"type": "word",
"position": 0
}
]
}
这篇关于Elasticsearch定制分析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文