Elasticsearch Analyzer不能替代使徒(')

时间:2019-05-22 08:04:07

标签: elasticsearch elasticsearch-analyzers

使用Elasticsearch v7.0
这是我已实现的分析器(http://phoenyx2:9200/search_dev/_settings?pretty=true):

{
    "search_dev": {
        "settings": {
            "index": {
                "refresh_interval": "30s",
                "number_of_shards": "1",
                "provided_name": "search_dev",
                "creation_date": "1558444846417",
                "analysis": {
                    "analyzer": {
                        "my_standard": {
                            "filter": [
                                "lowercase"
                            ],
                            "char_filter": [
                                "my_char_filter"
                            ],
                            "tokenizer": "standard"
                        }
                    },
                    "char_filter": {
                        "my_char_filter": {
                            "type": "mapping",
                            "mappings": [
                                "' => "
                            ]
                        }
                    }
                },
                "number_of_replicas": "1",
                "uuid": "hYz0ZlWFTDKearW1rpx8lw",
                "version": {
                    "created": "7000099"
                }
            }
        }
    }
}

我已经重新创建了整个索引,但分析仍然没有变化。
我也运行了这个:url(phoenyx2:9200/search_dev/_analyze

{
    "analyzer":"my_standard",
    "field":"stakeholderName",
    "text": "test't"
}

回复为:

{
    "tokens": [
        {
            "token": "test't",
            "start_offset": 0,
            "end_offset": 6,
            "type": "<ALPHANUM>",
            "position": 0
        }
    ]
}

我希望返回的令牌为“ testt

1 个答案:

答案 0 :(得分:1)

重新创建索引时,不足以在设置中定义新的分析器。

您还必须在映射中指定哪些字段使用哪个分析器,例如:

   "mappings":{
       "properties":{
          "stakeholderName": {
             "type":"text",
             "analyzer":"my_analyzer", 
         },
      }
   }

您正在映射(可能)如下:

   "mappings":{
       "properties":{
          "stakeholderName": {
             "type":"text",
         },
      }
   }

如果再次运行“分析”测试并删除该字段,则基本:

{
    "analyzer":"my_standard",
    "text": "test't"
}

您将获得:

{
  "token": "testt",
  "start_offset": 0,
  "end_offset": 6,
  "type": "<ALPHANUM>",
  "position": 0
}

如您所料,坏消息哥们,但您必须再次重新索引所有数据,这一次在映射中指定要用于每个字段的分析器,否则弹性将默认为每个标准分析器时间。