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:
|
|
The total number of documents. |
|
|
The number of documents that have at least one term for this field, or -1 if this measurement isn’t available on one or more shards. |
|
|
The percentage of documents that have at least one value for this field. This is a derived statistic and is based on the |
|
|
The sum of each term’s document frequency in this field, or -1 if this measurement isn’t available on one or more shards. Document frequency is the number of documents containing a particular term. |
|
|
The sum of the term frequencies of all terms in this field across all documents, or -1 if this measurement isn’t available on one or more shards. Term frequency is the total number of occurrences of a term in a particular document and 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 the min_value and max_value statistic. This option is only useful if the level option is set to indices. 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 the answer_count property for indices holding questions created in the year 2014:
POST _field_stats?level=indices
{
"fields" : ["answer_count"],
![]()
"index_constraints" : {
![]()
"creation_date" : {
![]()
"max_value" : {
![]()
"gte" : "2014-01-01T00:00:00.000Z"
},
"min_value" : {
![]()
"lt" : "2015-01-01T00:00:00.000Z"
}
}
}
}
对应ES5.5的源码部分:elasticsearch/search/lookup/IndexField.java
import org.apache.lucene.search.CollectionStatistics;
import org.elasticsearch.common.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 field
private 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 源码分析的更多相关文章
- Elasticsearch之源码分析(shard分片规则)
前期博客是 Elasticsearch之源码编译 (1)elasticsearch在建立索引时,根据id或(id,类型)进行hash,得到hash值之后再与该索引的分片数量取模,取模的值即为存入的分片 ...
- ElasticSearch Index操作源码分析
ElasticSearch Index操作源码分析 本文记录ElasticSearch创建索引执行源码流程.从执行流程角度看一下创建索引会涉及到哪些服务(比如AllocationService.Mas ...
- Elasticsearch源码分析 - 源码构建
原文地址:https://mp.weixin.qq.com/s?__biz=MzU2Njg5Nzk0NQ==&mid=2247483694&idx=1&sn=bd03afe5a ...
- ElasticSearch 启动时加载 Analyzer 源码分析
ElasticSearch 启动时加载 Analyzer 源码分析 本文介绍 ElasticSearch启动时如何创建.加载Analyzer,主要的参考资料是Lucene中关于Analyzer官方文档 ...
- Elasticsearch源码分析—线程池(十一) ——就是从队列里处理请求
Elasticsearch源码分析—线程池(十一) 转自:https://www.felayman.com/articles/2017/11/10/1510291570687.html 线程池 每个节 ...
- elasticsearch源码分析之search模块(server端)
elasticsearch源码分析之search模块(server端) 继续接着上一篇的来说啊,当client端将search的请求发送到某一个node之后,剩下的事情就是server端来处理了,具体 ...
- elasticsearch源码分析之search模块(client端)
elasticsearch源码分析之search模块(client端) 注意,我这里所说的都是通过rest api来做的搜索,所以对于接收到请求的节点,我姑且将之称之为client端,其主要的功能我们 ...
- Solr4.8.0源码分析(13)之LuceneCore的索引修复
Solr4.8.0源码分析(13)之LuceneCore的索引修复 题记:今天在公司研究elasticsearch,突然看到一篇博客说elasticsearch具有索引修复功能,顿感好奇,于是点进去看 ...
- 转-filebeat 源码分析
背景 在基于elk的日志系统中,filebeat几乎是其中必不可少的一个组件,例外是使用性能较差的logstash file input插件或自己造个功能类似的轮子:). 在使用和了解filebeat ...
随机推荐
- ionic start 又一次的出错
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\ ...
- html5——多媒体(一)
<audio> 1.autoplay 自动播放 2.controls 是否显不默认播放控件 3.loop 循环播放 4.preload 预加载 同时设置autoplay时些属性失效 5.由 ...
- JS——event
触发DOM上的某个事件时,会产生一个事件对象event,这个对象中包含着所有与事件有关的信息: 普通浏览器支持 event(传参),IE678支持 window.event(无参),兼容写法: < ...
- 8、scala面向对象编程之对象
1. Object 2.伴生对象 3.让object继承抽象类 4.apply方法 5.main方法 6.用object实现枚举功能 1. Object Object,相当于class的单个实例, ...
- PowerDesigner16逆向工程生成PDM列注释(My Sql5.0模版)
一.编辑当前DataBase 选择DataBase——>edit Current DBMS...弹出如下对话框: 如上图,先解释一下: 根据红颜色框从上往下解释一下. 第一个红框是对应的修改的 ...
- 使用ScriptManager服务器控件前后台数据交互
前台页面信息: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFor ...
- Win10电脑如何更改开机启动项
https://jingyan.baidu.com/article/5970355284f0458fc1074049.html
- 一文读懂架构师都不知道的isinstance检查机制
起步 通过内建方法 isinstance(object, classinfo) 可以判断一个对象是否是某个类的实例.但你是否想过关于鸭子协议的对象是如何进行判断的呢? 比如 list 类的父类是继 o ...
- Burnside引理和polay计数 poj2409 Let it Bead
题目描述 "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you ...
- sysbench测试阿里云CPU
参考 https://wiki.mikejung.biz/Benchmarking 买了一个1核的ECS,测试一下CPU性能 第一次是只用1个thread去跑 [root@iZwz9fy718twfi ...