Token计数字段类型
一个token计数字段类型存储字符串中分析出的token数量。
示例
创建一个具有token计数字段的映射:
PUT testindex
{
"mappings": {
"properties": {
"sentence": {
"type": "text",
"fields": {
"num_words": {
"type": "token_count",
"analyzer": "english"
}
}
}
}
}
}
索引包含文本字段的三个文档:
PUT testindex/_doc/1
{ "sentence": "To be, or not to be: that is the question." }
PUT testindex/_doc/2
{ "sentence": "All the world’s a stage, and all the men and women are merely players." }
PUT testindex/_doc/3
{ "sentence": "Now is the winter of our discontent." }
搜索少于10个单词的句子:
GET testindex/_search
{
"query": {
"range": {
"sentence.num_words": {
"lt": 10
}
}
}
}
响应包含一条匹配的句子:
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "testindex",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"sentence" : "Now is the winter of our discontent."
}
}
]
}
}
参数
以下表格列出了token count字段类型接受的参数。analyzer参数是必需的;所有其他参数都是可选的。
| 参数 | 描述 |
|---|---|
| analyzer | |
| 该字段使用的分析器。指定不带分词过滤器的分析器以获得最佳性能。必需。 | |
| boost | 浮点值,指定该字段对相关度得分的权重。大于1.0的值会增加字段的权重。介于0.0和1.0之间的值会降低字段的权重。默认值为1.0。 |
| doc_values | 布尔值,指定字段是否应存储在磁盘上以便用于聚合、排序或脚本。默认值为false。 |
| enable_position_increments | 布尔值,指定是否应计算位置增量。为了避免删除停用词,请将此字段设置为false。默认为true。 |
| index | 布尔值,用于指定字段是否可搜索。默认值为true。 |
| null_value | 一个用于替换null的值。必须与字段类型相同。如果未指定此参数,当字段的值为null时,字段被视为缺失。默认为null。 |
| store | 布尔值,指定字段值是否应存储并可从_source字段单独检索。默认为false。 |