原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/current/token-count.html
译文链接 :http://www.apache.wiki/pages/viewpage.action?pageId=10030674
简述
类型为token_count的字段是一个接受字符串值的integer字段,对它们进行分析,然后对字符串中的token数进行索引。
示例
例如:
PUT my_index{"mappings": {"my_type": {"properties": {"name": {"type": "text","fields": {"length": {"type": "token_count","analyzer": "standard"}}}}}}}PUT my_index/my_type/1{ "name": "John Smith" }PUT my_index/my_type/2{ "name": "Rachel Alice Williams" }GET my_index/_search{"query": {"term": {"name.length": 3}}}
|
| name字段是使用默认standard分析器的分析字符串字段。 |
|
| name.length字段是一个token_count 多字段 ,它将在name字段中索引token的数量。 |
|
| 此查询仅匹配包含Rachel Alice Williams的文档,因为它包含三个token。 |

在技术上, token_count类型对位置增量进行求和,而不是对token计数。 这意味着即使分析仪滤除停止词,它们也包括在计数中。
参数
token_count字段接受以下参数:
| analyzer | 应该用于分析字符串值的分析器 。必须值。 为获得最佳性能,请使用不带token过滤器的分析器。 |
| boost | 映射字段级查询时间提升。 接受一个浮点数,默认为1.0 。 |
| doc_values | 该字段是否应该以多列的方式存储在磁盘上,以便以后可以将其用于排序,聚合或脚本化?接受true (默认)或false 。 |
| index | 应该可以搜索该字段吗? 接受not_analyzed (默认)和no 。 |
| include_in_all | 字段值是否应包含在_all字段中? 接受true或false 默认为false 。 注意:如果为true ,则将字符串值添加到_all,而不是计算的token数量。 |
| null_value | 接受与替换任何显式null值的字段相同type的数值。 默认为null ,这意味着该字段被视为丢失。 |
| store | 字段值是否应与_source字段分开存储和检索。 接受true或false (默认)。 |
