因此,我很确定我在语法中缺少某些内容,但似乎无法弄清楚到底是什么。我正在尝试创建定义为here的电话号码模式捕获令牌过滤器。它说先定义一个关键字过滤器,然后在顶部应用模式捕获令牌。这就是我所做的:
{
"mappings": {
"_doc": {
"properties": {
"phone": {
"type": "text",
"analyzer": "my_phone_analyzer"
}
}
}
},
"settings": {
"analysis": {
"analyzer": {
"my_phone_analyzer": {
"type": "custom",
"tokenizer": "keyword",
"char_filter": [
"phone_number"
]
}
}
},
"char_filter": {
"phone_number": {
"type": "pattern_capture",
"preserve_original": 1,
"patterns": [
"1(\\d{3}(\\d+))"
]
}
}
}
}
这是导致以下错误的原因:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.char_filter.phone_number.patterns] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
}
],
"type": "illegal_argument_exception",
"reason": "unknown setting [index.char_filter.phone_number.patterns] please check that any required plugins are installed, or check the breaking changes documentation for removed settings",
"suppressed": [
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.char_filter.phone_number.preserve_original] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
},
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.char_filter.phone_number.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
}
]
},
"status": 400
}
如果有人能指出我在做什么错,那太好了!
答案 0 :(得分:2)
您创建filter.equals()
的配置存在一些问题。
my_phone_analyzer
,在char过滤器中不允许使用https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-pattern-capture-tokenfilter.html
pattern_capture
设置不使用preserve_original
值,而是使用1
,true
作为值。
因此,考虑到所有这些因素,我能够使用与您相同的设置来创建false
。
my_phone_analyzer
让我知道您是否遇到任何问题。
答案 1 :(得分:2)
您提到的链接看起来很旧。
pattern_capture
不再适用于char_filter
,而仅适用于token filter
以下是在5.x以上版本使用Elasticsearch时的映射方式
PUT <your_index_name>
{
"mappings":{
"_doc":{
"properties":{
"phone":{
"type":"text",
"analyzer":"my_phone_analyzer"
}
}
}
},
"settings":{
"analysis":{
"analyzer":{
"my_phone_analyzer":{
"type":"custom",
"tokenizer":"keyword",
"filter":[
"phone_number"
]
}
},
"filter":{
"phone_number":{
"type":"pattern_capture",
"preserve_original":true,
"patterns":[
"1(\\d{3}(\\d+))"
]
}
}
}
}
}
您可以使用Analyze API
来查看生成的令牌,如下所述:
POST <your_index_name>/_analyze
{
"analyzer": "my_phone_analyzer",
"text": "19195557321"
}
{
"tokens" : [
{
"token" : "19195557321",
"start_offset" : 0,
"end_offset" : 11,
"type" : "word",
"position" : 0
},
{
"token" : "9195557321",
"start_offset" : 0,
"end_offset" : 11,
"type" : "word",
"position" : 0
},
{
"token" : "5557321",
"start_offset" : 0,
"end_offset" : 11,
"type" : "word",
"position" : 0
}
]
}
希望有帮助!