当前位置: 移动技术网 > 科技>人工智能>云计算 > ElasticSearch之termvector介绍

ElasticSearch之termvector介绍

2018年03月19日  | 移动技术网科技  | 我要评论

termvector会获取document中的某个field内的各个term的统计信息。

一 term的基本信息

# term_freq:在在该字段中的频率

# position:词在该字段中的位置

# start_offset:从什么偏移量开始的

# end_offset: 到什么偏移量结束

二 term的统计信息

如果启用了term的统计信息,即term_statistics设为true,那么有哪些统计信息呢?

# doc_freq: 该词在文档中出现的频率

# ttf:total term frequency的缩写,一个term在所有document中出现的频率

三 字段的统计信息

如果启用了字段统计信息,即field_statistics设为true,那么有哪些统计信息呢?

# sum_doc_freq: 一个字段中所有term的文档频率之和

# doc_count: 有多少个文档包含这个字段

# sum_ttf:sum total term frequency的缩写,一个字段中的每一个term的在所有文档出现之和

term statistics和field statistics并不精准,不会被考虑有的doc可能被删除了

四 采集term信息的方式

采集term信息的方式有两种:index-time 和 query-time

4.1 index-time方式

需要在mapping配置一下,然后建立索引的时候,就直接生成这些词条和文档的统计信息

PUT /website

{

"mappings": {

"article":{

"properties":{

"text":{

"type": "text",

"term_vector": "with_positions_offsets",

"store": "true",

"analyzer" : "fulltext"

}

}

}

},

"settings": {

"analysis": {

"analyzer": {

"fulltext":{

"type": "custom",

"tokenizer": "whitespace",

"filter": [

"lowercase",

"type_as_payload"

]

}

}

}

}

}

4.2 query-time方式

即之前没有在mapping里配置过,而是通过查询的方式产生这些统计信息

POST /ecommerce/music/1/_termvectors

{

"fields":["desc"],

"offsets":true,

"payloads":true,

"positions":true,

"term_statistics":true,

"field_statistics" : true

}

五 手动指定analyzer来生成termvector

我么可以通过指定per_field_analyzer设置一个分词器对该字段文本进行分词。

POST /ecommerce/music/1/_termvectors

{

"fields":["desc"],

"offsets":true,

"payloads":true,

"positions":true,

"term_statistics":true,

"field_statistics" : true,

"per_field_analyzer":{

"text":"standard"

}

}

六 过滤term的统计信息

我们可以根据term的统计信息,过滤出我么想看的统计结果,比如过滤掉一些出现频率过低的term,比如我要过滤出该字段最多只有10个term,而且那些term在该字段中出现的频率为2,且

POST /ecommerce/music/1/_termvectors

{

"fields":["desc"],

"offsets":true,

"payloads":true,

"positions":true,

"term_statistics":true,

"field_statistics" : true,

"filter":{

"max_num_terms":10,

"min_term_freq" : 2,

"min_doc_freq" : 1

}

}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网