糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > elasticsearch _field_stats 源码分析

elasticsearch _field_stats 源码分析

时间:2021-04-30 05:30:55

相关推荐

elasticsearch _field_stats 源码分析

_field_stats实现的功能:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-field-stats.html

获取索引下字段的统计信息,如下表,同时还可以针对这些统计值进行过滤:

Field statistics

The field stats api is supported on string based, number based and date based fields and can return the following statistics per field:

Field stats index constraints ——kibana里按照时间范围进行绘图就是用到这个。

Field stats index constraints allows to omit all field stats for indices that don’t match with the constraint. An index constraint can exclude indices' field stats based on themin_valueandmax_valuestatistic. This option is only useful if theleveloption is set toindices. Fields that are not indexed (not searchable) are always omitted when an index constraint is defined.

For example index constraints can be useful to find out the min and max value of a particular property of your data in a time based scenario. The following request only returns field stats for theanswer_countproperty for indices holding questions created in the year :

POST _field_stats?level=indices{"fields" : ["answer_count"],

"index_constraints" : {

"creation_date" : {

"max_value" : {

"gte" : "-01-01T00:00:00.000Z"},"min_value" : {

"lt" : "-01-01T00:00:00.000Z"}}}}

对应ES5.5的源码部分:elasticsearch/search/lookup/IndexField.java

importorg.apache.lucene.search.CollectionStatistics;import mon.util.MinimalMap;import java.io.IOException;import java.util.HashMap;import java.util.Map;/*** Script interface to all information regarding a field.* */public class IndexField extends MinimalMap<String, IndexFieldTerm> {/** TermsInfo Objects that represent the Terms are stored in this map when* requested. Information such as frequency, doc frequency and positions* information can be retrieved from the TermInfo objects in this map.*/private final Map<String, IndexFieldTerm> terms = new HashMap<>();// the name of this fieldprivate final String fieldName;/** The holds the current reader. We need it to populate the field* statistics. We just delegate all requests there*/private final LeafIndexLookup indexLookup;/** General field statistics such as number of documents containing the* field.*/private final CollectionStatistics fieldStats;public IndexField(String fieldName, LeafIndexLookup indexLookup) throws IOException {assert fieldName != null;this.fieldName = fieldName;assert indexLookup != null;this.indexLookup = indexLookup;fieldStats= this.indexLookup.getIndexSearcher().collectionStatistics(fieldName);}/* get number of documents containing the field */public long docCount() throws IOException {return fieldStats.docCount();}/* get sum of the number of words over all documents that were indexed */public long sumttf() throws IOException {return fieldStats.sumTotalTermFreq();}/** get the sum of doc frequencies over all words that appear in any document* that has the field.*/public long sumdf() throws IOException {return fieldStats.sumDocFreq();}// 。。。。。。。}

如果觉得《elasticsearch _field_stats 源码分析》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。