_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 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();}// 。。。。。。。
}

转载于:https://www.cnblogs.com/bonelee/p/8408891.html

elasticsearch _field_stats 源码分析相关推荐

  1. Elasticsearch CCR源码分析(补充)

    接上篇TODO Elasticsearch CCR源码分析 上篇TODO: http请求(ccr/follow)接收到后,follow集群节点开始全量同步,是以snapshot的模式去拉leader集 ...

  2. Elasticsearch CCR源码分析

    本文基于Elasticsearch6.8.5版本 ES使用的是Guice框架,依赖注入和暴露接口的方式和Spring差距较大,可先查看guice框架 节点启动过程: org/elasticsearch ...

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

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

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

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

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

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

  6. elasticsearch index、create和update的源码分析

    https://segmentfault.com/a/1190000011272749 社区里面有人问了如下一个问题: 执行 bulk 索引文档的时候,用 index 或者 create 类型并且自定 ...

  7. 【Elasticsearch源码】CCR源码分析(一)

    1 CCR的基本概念 什么是CCR? CCR( cross-cluster replication):跨集群复制是ES 6.5发布的一个新的特性:可以将两个集群中的数据进行远程复制. 集群复制类似于数 ...

  8. 【Elasticsearch源码】CCR源码分析(二)

    接上一篇:[Elasticsearch源码]CCR源码分析(一). sendShardChangesRequest方法最终进入到ShardChangesAction.TransportAction#s ...

  9. Kubernetes StatefulSet源码分析

    2019独角兽企业重金招聘Python工程师标准>>> Author: xidianwangtao@gmail.com,Based on Kubernetes 1.9 摘要:Kube ...

最新文章

  1. 算法笔记-归并算法面试题、逆序数问题
  2. jsp中的contentType与pageEncoding的区别和作用
  3. 梦幻西游服务器维护到几点,《梦幻西游》维护到几点 梦幻西游维护时间
  4. 令人叫绝的EXCEL函数功能
  5. LOAM_velodyne学习(一)
  6. react学习(69)--置空操作
  7. LeetCode 816. 模糊坐标
  8. cookie购物车php简单,cookie的优化与购物车实例
  9. SLAM Cartographer(14)Global SLAM的主线业务
  10. 【leetcode刷题笔记】Roman to Integer
  11. Node.js:封装Node通用web容器
  12. LwIP协议栈——网络接口管理
  13. java建设银行支付_基于JAVA的建设银行账目管理系统的设计
  14. Win10问题篇:使用微PE装机。(完整版教程)
  15. Windows 7下可用的“超级终端”——Hypertrm和SecureCRT
  16. 计算机图形学必读的10本书
  17. Xcode 8.0 Beta发布,详解Swift语言的重大变化
  18. 电脑运行速度(卡不卡)的决定因素
  19. 计算机应用研究是北大核心吗,计算机应用研究 CSCD核心期刊北大核心期刊统计源期刊...
  20. 轻量级虚拟桌面基础架构(VDI) 解决方案降低 IT 成本并保护知识产权

热门文章

  1. kafka消息存储与partition副本原理(二)
  2. git如何忽略已经提交的文件 (.gitignore文件无效)
  3. 试玩UML(User Mode Linux)
  4. flink链接mysql_flink 将mysql作为Source和Sink的代码示例
  5. python爬虫源码下载 视频_Python爬虫下载视频文件部分源码
  6. 计算机论文数据建模怎么写,如何撰写建模论文?
  7. java面向对象程序设计第三版_JAVA面向对象程序设计之创建型设计模式
  8. python中全局变量和局部变量关键字_Python中全局变量和局部变量的理解与区别
  9. mysql 中的 utf_Mysql中的utf-8竟然是假的!
  10. linux查看安装的所有内核,Linux怎么查看系统已安装内核