_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:

max_doc

The total number of documents.

doc_count

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.

density

The percentage of documents that have at least one value for this field. This is a derived statistic and is based on the max_doc and doc_count.

sum_doc_freq

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.

sum_total_term_freq

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 源码分析的更多相关文章

  1. Elasticsearch之源码分析(shard分片规则)

    前期博客是 Elasticsearch之源码编译 (1)elasticsearch在建立索引时,根据id或(id,类型)进行hash,得到hash值之后再与该索引的分片数量取模,取模的值即为存入的分片 ...

  2. ElasticSearch Index操作源码分析

    ElasticSearch Index操作源码分析 本文记录ElasticSearch创建索引执行源码流程.从执行流程角度看一下创建索引会涉及到哪些服务(比如AllocationService.Mas ...

  3. Elasticsearch源码分析 - 源码构建

    原文地址:https://mp.weixin.qq.com/s?__biz=MzU2Njg5Nzk0NQ==&mid=2247483694&idx=1&sn=bd03afe5a ...

  4. ElasticSearch 启动时加载 Analyzer 源码分析

    ElasticSearch 启动时加载 Analyzer 源码分析 本文介绍 ElasticSearch启动时如何创建.加载Analyzer,主要的参考资料是Lucene中关于Analyzer官方文档 ...

  5. Elasticsearch源码分析—线程池(十一) ——就是从队列里处理请求

    Elasticsearch源码分析—线程池(十一) 转自:https://www.felayman.com/articles/2017/11/10/1510291570687.html 线程池 每个节 ...

  6. elasticsearch源码分析之search模块(server端)

    elasticsearch源码分析之search模块(server端) 继续接着上一篇的来说啊,当client端将search的请求发送到某一个node之后,剩下的事情就是server端来处理了,具体 ...

  7. elasticsearch源码分析之search模块(client端)

    elasticsearch源码分析之search模块(client端) 注意,我这里所说的都是通过rest api来做的搜索,所以对于接收到请求的节点,我姑且将之称之为client端,其主要的功能我们 ...

  8. Solr4.8.0源码分析(13)之LuceneCore的索引修复

    Solr4.8.0源码分析(13)之LuceneCore的索引修复 题记:今天在公司研究elasticsearch,突然看到一篇博客说elasticsearch具有索引修复功能,顿感好奇,于是点进去看 ...

  9. 转-filebeat 源码分析

    背景 在基于elk的日志系统中,filebeat几乎是其中必不可少的一个组件,例外是使用性能较差的logstash file input插件或自己造个功能类似的轮子:). 在使用和了解filebeat ...

随机推荐

  1. VC使用CryptoAPI计算MD5

    // md5.h #include <tchar.h> #include <wincrypt.h> // 计算Hash,成功返回0,失败返回GetLastError() // ...

  2. Centos 安装 Moosefs文件系统

    一.环境介绍Moosefs master:192.168.55.148Moosefs Metalogger:192.168.55.149Moosefs Chunk-01:192.168.55.150M ...

  3. Mapreduce代码疑点(1)

    一.Hadoop MultipleInputs.addInputPath 读取多个路径 https://blog.csdn.net/t1dmzks/article/details/76473905 M ...

  4. 模拟Spring容器的getBean方法(Maven工程)

    Spring容器的getBean方法是通过反射机制实现的,下面的测试程序模拟getBean的实现原理. 步骤一:pom.xml文件配置解析XML文件的dom4j.jar 步骤二:XML文件中配置bea ...

  5. js兼用性

    1.document.formName.item("itemName") 问题 说明:IE下,可以使用document.formName.item("itemName&q ...

  6. 00.不规则json序列化使用eval、demjson

    有下面一段字符串 import json str0 = '[{"name":"白云大道营业厅","siteaddr":"x...& ...

  7. windows和linux下 Python2,Python3 的环境及安装

    目录 windows和linux下 Python2,Python3 的环境及安装 window下安装 一. 手动安装 二. pip安装 linux下 安装 更新Python 笔者有话 windows和 ...

  8. emacs 定制进缩风格

    纵览 emacs 文档中描述,进缩风格实现只需要两步:第一步,根据内容与上下文找到对应的进缩风格的类别:第二步,依据进缩风格决定的表达式锚点的进缩偏移.下面我们对 cc-mode 风格定制加以说明. ...

  9. mysql-索引、导入、导出、备份、恢复

    1.索引 索引是一种与表有关的结构,它的作用相当于书的目录,可以根据目录中的页码快速找到所需的内容. 当表中有大量记录时,若要对表进行查询,没有索引的情况是全表搜索:将所有记录一一取出,和查询条件进行 ...

  10. centOS下安装mysql workbench详细步骤

    step0:安装mysql 在按照workbench之前,先安装mysql.指令是 yum install mysql mysql-server mysql-libs mysql-server 关于m ...