ElasticSearch之term vector

来源:互联网 发布:大非农数据一定准确吗 编辑:程序博客网 时间:2024/06/06 10:04

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

    }

}

原创粉丝点击