多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# Keep Types Token Filter(保留指定类型过滤器) 原文链接 : [https://www.elastic.co/guide/en/elasticsearch/reference/5.4/analysis-keep-types-tokenfilter.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/analysis-keep-types-tokenfilter.html) 译文链接 : [http://www.apache.wiki/display/Elasticsearch](http://www.apache.wiki/display/Elasticsearch) 贡献者 : [李亚运](/display/~liyayun),[ApacheCN](/display/~apachecn),[Apache中文网](/display/~apachechina) ## 简述 当type为`keep_types时`,过滤器将只保留包含在预定义集合中的token。 ## 参数 | types | 要保留的类型列表 | ## 示例 你可以这样设置: ``` PUT /keep_types_example { "settings" : { "analysis" : { "analyzer" : { "my_analyzer" : { "tokenizer" : "standard", "filter" : ["standard", "lowercase", "extract_numbers"] } }, "filter" : { "extract_numbers" : { "type" : "keep_types", "types" : [ "<NUM>" ] } } } } } ``` 并用下述文本进行测试: ``` POST /keep_types_example/_analyze { "analyzer" : "my_analyzer", "text" : "this is just 1 a test" } ``` 返回结果: ``` { "tokens": [ { "token": "1", "start_offset": 13, "end_offset": 14, "type": "<NUM>", "position": 3 } ] } ``` 注意输出中只有`&lt;NUM&gt;token(只有数字1,其他文本都被忽略了)`。