Elasticsearch 高手之路
  • Introduction
  • First Chapter
  • 1.ElasticSearch 5.x 安装
    • 1.1.Window 环境
    • 1.2.Linux 环境
  • 2.基础学前班
  • 3.基础
    • 3.1.配置文件
    • 3.2.Mapping
      • 3.2.1.字段的数据类型
        • 3.2.1.1.核心数据类型
        • 3.2.1.2.复合数据类型
        • 3.2.1.3.Geo地理数据类型
        • 3.2.1.4.特定数据类型
      • 3.2.2.Meta-Fields(元字段)
        • _index,_uid,_type,_id 元字段
        • _source,_size 元字段
        • _all, _field_names元字段
        • _parent,_routing 元字段
        • _meta 元字段
      • 3.2.3.Mapping parameters(映射参数)
        • analyzer(分析器)
        • normalizer(归一化)
        • boost(提升)权重
        • Coerce(强制类型转换)
        • copy_to(合并参数)
        • doc_values(文档值)
        • dynamic(动态设置)
        • enabled(开启字段)
        • fielddata(字段数据)
        • format (日期格式)
        • ignore_above(忽略超越限制的字段)
        • ignore_malformed(忽略格式不对的数据)
        • include_in_all(_all 查询包含字段)
        • index_options(索引设置)
        • index (索引)
        • fields(字段)
        • norms (标准信息)
        • null_value(空值)
        • position_increment_gap(短语位置间隙)
        • properties (属性)
        • search_analyzer (搜索分析器)
        • similarity (相似度模型)
        • store(存储)
        • term_vectors(词根信息)
      • 3.2.4.Dynamic Mapping(动态映射)
        • _default_ mapping(mapping中的_default_)
        • Dynamic field mapping(动态字段映射)
        • Dynamic templates(动态模板)
        • Override default template(覆盖默认模板)
    • 3.3. Analysis(分析)
      • 3.3.1.Anatomy of an analyzer(分析器的分析)
      • 3.3.2.Testing analyzers(测试分析器)
      • 3.3.3.Analyzers(分析器)
        • Configuring built-in analyzers(配置内置分析器)
        • Standard Analyzer(标准分析器)
        • Simple Analyzer(简单分析器)
        • Whitespace Analyzer(空格分析器)
        • Stop Analyzer(停止词分词器)
        • Keyword Analyzer(关键词分析器)
        • Pattern Analyzer(模式分析器)
        • Language Analyzers(语言分析器)
        • Fingerprint Analyzer(指纹分析器)
        • Custom Analyzer(自定义分析器)
      • 3.3.4. Tokenizers(分词器)
        • Standard Tokenizer(标准分词器)
        • Letter Tokenizer
        • Lowercase Tokenizer (小写分词器)
        • Whitespace Tokenizerr (空格分词器)
        • UAX URL Email Tokenizer
        • Classic Tokenizer
        • Thai Tokenizer(泰语分词器)
        • NGram Tokenizer
        • Edge NGram Tokenizer
        • Keyword Tokenizer(关键词分词器)
        • Pattern Tokenizer(模式分词器)
        • Path Hierarchy Tokenizer(路径层次分词器)
      • 3.3.5.Token Filters(词语过滤器)
      • 3.3.5.补充1:Token Filters(词语过滤器)
      • 3.3.5.补充2:Token Filters(词语过滤器)
      • 3.3.6.Character Filters(字符过滤器)
        • HTML Strip Character Filter(HTML标签过滤)
        • Mapping Character Filter(字符替换映射)
        • Pattern Replace Character Filter(正则替换字符)
    • 3.4. APIs
      • 3.4.1.索引 APIs (Indices APIs)
        • 创建/删除/获取->索引
        • 启动关闭/缩小/滚动->索引
        • 提交/获取/获取字段->映射
        • 索引->别名/是否存在/类型存在
        • 更新索引/获取->设置(未完成)
        • 分析器、索引模板(未完成)
        • Shadow replica indices 卷影副本索引
        • 索引->统计信息/段
        • 索引->恢复/分片存储
        • 清理缓存/刷新/同步刷新
        • 重新加载/强制合并
      • 3.4.2.文档 APIs (Document APIs)
        • 读写文档(Reading and Writing documents)
        • 索引文档 API
        • 获取/批量获取->文档
        • 删除/根据查询API删除
        • 更新/根据查询API更新
        • Bulk API(批量操作)
        • Reindex API(复制索引)
        • Term Vectors(词条向量)/Multi termvectors API
        • ?refresh
      • 3.4.3.搜索 APIs (Search APIs)
        • Search / URI Search
        • Request Body Search(未完成)
          • Query / From / Size
          • Sort / Source filtering
          • Fields / Script Fields / Doc value Fields
          • Post filter
          • Highlighting
          • Rescoring / Search Type
          • Scroll
          • Preference / Explain
          • Version / Index Boost
          • min_score / Named Queries
          • Inner hits / Search After
          • Field Collapsing 字段折叠
        • Search 模板/Multi Search 模板
        • Search Shards API
        • Suggesters
          • Term suggester
          • Phrase Suggester
          • Completion Suggester
          • Context Suggester
          • 返回suggester的类型
        • Multi Search API
        • Count API
        • Validate API
        • Explain API
        • Profile API
          • Profiling Queries
          • Profiling Aggregations
          • Profiling Considerations
        • Percolator / Field stats API
        • Field Capabilities API
    • 3.5.Query DSL(DSL方式查询)
      • 3.5.1.查询和过滤上下文
      • 3.5.2.Match All 查询
      • 3.5.3.全文搜索(Full Text Search)
        • 匹配查询(Match Query)
        • 短语匹配查询(Match Phrase Query)
        • 短语前缀匹配查询(Match Phrase Prefix Query)
        • 多字段查询(Multi Match Query)
        • 常用术语查询(Common Terms Query)
        • (Query String Query) 未完成
      • 3.5.4.Term级别查询(Term level queries)
        • Term 查询
        • Terms 查询
        • Range 查询(范围查询)
        • Exists 查询(非空值查询)
        • Prefix 查询(前缀查询)
        • Wildcard 查询(通配符查询)
        • Regexp 查询(正则表达式查询)
        • Fuzzy 查询(模糊查询)
        • Type Query(类型查询)
        • Ids Query(ID 查询)
      • 3.5.5.复合查询(Compound queries)
        • Constant Score 查询
        • Bool 查询
        • Dis Max 查询
        • Function Score 查询
        • Boosting 查询
        • Indices 查询
      • 3.5.6.Joining 查询(连接查询)
        • Nested Query(嵌套查询)
        • Has Child Query
        • Has Parent Query
        • Parent Id Query
      • 3.5.7.地理位置查询 (Geo queries)
        • GeoShape Query(地理形状查询)
        • Geo Bounding Box Query(地理边框查询)
        • Geo Distance Query(地理距离查询)
        • Geo Distance Range Query(地理距离范围查询)
        • Geo Polygon Query(地理多边形查询)
      • 3.5.8.专业查询(Specialized queries)
      • 3.5.9.Span 查询
        • Span Term 查询
        • Span Multi Term 查询
        • Span First 查询
        • Span Near 查询
        • Span Or 查询
        • Span Not 查询
        • Span Containing 查询
        • Span Within 查询
        • Span Field Masking 查询
    • 3.6.Aggregations(聚合分析)
      • 3.6.1.量度聚合(Metric Aggregations)
        • 平均值聚合(Avg Aggregation)
        • 基数聚合(Cardinality Aggregation)
        • 扩展统计聚合( Extended Stats Aggregation)
        • 地理边界聚合(Geo Bounds Aggregation)
        • 地理重心聚合(Geo Centroid Aggregation)
        • 最大值聚合(Max Aggregation)
        • 最小值聚合(Min Aggregation)
        • Percentiles Aggregation
        • Percentile Ranks Aggregation
        • Scripted Metric Aggregation
        • Stats Aggregation
        • 总和聚合(Sum Aggregation)
        • Top hits Aggregation
        • Value Count Aggregation
      • 3.6.2.桶聚合(Bucket Aggregations)
        • 邻接矩阵聚合(Adjacency Matrix Aggregation)
        • Children Aggregation
        • 日期直方图聚合(Date Histogram Aggregation)
        • 日期范围聚合(Date Range Aggregation)
        • 多元化的采样器聚集(Diversified Sampler Aggregation)
        • 过滤器聚合(Filter Aggregation)
        • 多过滤器聚合(Filters Aggregation)
        • 地理距离聚合(Geo Distance Aggregation)
        • GeoHash网格聚合(GeoHash grid Aggregation)
        • 全局聚合(Global Aggregation)
        • 直方图聚合(Histogram Aggregation)
        • IP范围聚合(IP Range Aggregation)
        • 丢失字段聚合(Missing Aggregation)
        • 嵌套聚合(Nested Aggregation)
        • 范围聚合(Range Aggregation)
        • Reverse nested Aggregation
        • 采样聚合(Sampler Aggregation)
        • Significant Terms Aggregation
      • 3.6.3.管道聚合(Pipeline Aggregations)
        • 平均值桶聚合( Avg Bucket Aggregation)
        • 导数聚合(Derivative Aggregation)
        • 最大值桶聚合(Max Bucket Aggregation)
        • 最小值桶聚合(Min Bucket Aggregation)
        • 总和桶聚合(Sum Bucket Aggregation)
        • 统计桶聚合(Stats Bucket Aggregation)
        • 扩展信息桶聚合(Extended Stats Bucket Aggregation)
        • 百分数桶聚合(Percentiles Bucket Aggregation)
        • Moving Average Aggregation
        • 累积汇总聚合(Cumulative Sum Aggregation)
        • 桶脚本聚合(Bucket Script Aggregation)
        • 桶选择器聚合(Bucket Selector Aggregation)
        • 串行差异聚合(Serial Differencing Aggregation)
      • 3.6.4.矩阵聚合(Matrix Aggregations)
        • 矩阵统计(Matrix Stats)
      • 3.6.5.缓存频繁聚合(Caching heavy aggregations)
      • 3.6.6.仅返回需要聚合的结果(Returning only aggregation results)
      • 3.6.7.聚合元数据(Aggregation Metadata)
      • 3.6.8.返回聚合的类型(Returning the type of the aggregation)
    • Glossary of terms (词汇表)
    • 未完成的任务
  • 4.基础补充总结
    • 3.2.Mapping
    • 3.3.分析器与定义自己的分析器(Analyzer)
  • 原理
  • 实战
    • 结构化搜索
    • 聚合分析
    • 数据建模
    • 应用场景
  • PHP API
    • 安装与快速入门
    • 配置
    • 实战
  • 资料
  • 笔记
    • 1.x 升级 2.x
Powered by GitBook
On this page
  • Custom date formats (标准的日期格式)
  • Built In Formats (以格式化构建)

Was this helpful?

  1. 3.基础
  2. 3.2.Mapping
  3. 3.2.3.Mapping parameters(映射参数)

format (日期格式)

Previousfielddata(字段数据)Nextignore_above(忽略超越限制的字段)

Last updated 5 years ago

Was this helpful?

在JSON 文档中,日期表示为字符串.Elasticsearch 使用一组预先配置的格式来识别和解析这些字符串表示为 milliseconds-since-the-epoch in UTC.

除了内置格式,你可以使用熟悉的yyyy/MM/dd语法指定自己的自定义格式.

curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "date": {
          "type":   "date",
          "format": "yyyy-MM-dd"
        }
      }
    }
  }
}
'

支持日期值的许多API还支持日期数学表达式,例如now-1m/d,即当前时间,减去一个月,向下舍入到最近的一天.

tip:

格式设置在相同索引中相同名称的字段要有相同的设置.可以使用在现有字段上更新其值.

Custom date formats (标准的日期格式)

Built In Formats (以格式化构建)

以下大多数日期都有严格的伴随日期,这意味着,本周的年月日必须有前置的零数字才有效.这意味着,像5/11/1这样的日期是无效的,你需要制定完整的日期,例如2005/11/01。所以,你需要指定strict_date_optional_time(严格的日期选择) 来代替 date_optional_time.

下表列出了支持的所有默认ISO格式:

epoch_millis

一个毫秒的格式化程序.请注意,这个时间戳受 Java Long.MIN_VALUE和Long.MAX_VALUE限制.

epoch_second

.一个秒的格式化程序.请注意,时间戳受 Java Long.MIN_VALUE和Long.MAX_VALUE限制.MAX_VALUE除以1000(一秒钟的毫秒数).

通用 ISO 日期时间解析器,其中日期是必需的,时间是可选的。

一个对完整日期的格式化,四位数字年份,两位数字的月份,两位数字的日期: yyyMMdd

basic_date_time

一个包含基本日期和时间的格式化程序,通过'T'分割:yyyyMMdd'T'HHmmss.SSSZ.

basic_date_time_no_millis

一个包含基本日期和时间且没有毫秒的格式化程序,通过 ‘T’ 分割:yyyyMMdd'T'HHmmssZ.

basic_ordinal_date

一个用于 ordinal date的格式化程序,使用四位数字的年份和三位数的日期,yyyyDDD。

basic_ordinal_date_time

一个用于完整的 ordinal日期和时间的格式化程序,使用四位数的年份和三位数的日期: yyyyDDD'T'HHmmss.SSSZ.

basic_ordinal_date_time_no_millis

一个用于完整的 ordinal 日期和时间且没有毫秒的格式化程序,使用四位数的年份和三位数的日期: yyyyDDD'T'HHmmssZ.

basic_time

一个两位数的小时,两位数的分钟,两位数的秒,三位数的毫秒以及时间偏移量的格式化程序:HHmmss.SSSZ.

basic_time_no_millis

一个两位数的小时,两位数的分钟,两位数的秒以及时间偏移量的格式化程序:HHmmssZ

basic_t_time

一个两位数的小时,两位数的分钟,两位数的秒,三位数的毫秒以及以T为前缀的时区:'T'HHmmss.SSSZ.

basic_t_time_no_millis

一个两位数的小时,两位数的分钟,两位数的秒以及以T为前缀的时区:'T'HHmmssZ.

basic_week_date or strict_basic_week_date

一个四位数的weekyear,两位数的周数,一位数的天数:xxxx'W'wwe。

basic_week_date_time or strict_basic_week_date_time

一个包含基础的 weekyear 日期和时间的格式化程序,通过T分割: xxxx'W'wwe'T'HHmmss.SSSZ.

basic_week_date_time_no_millis or strict_basic_week_date_time_no_millis

一个包含基础的 weekyear 日期和时间且不包含毫秒的格式化程序,通过T分割 :xxxx'W'wwe'T'HHmmssZ.

date or strict_date

一个完整日期的格式化程序,四位数的年,两位数的月,两位数的天: yyyy-MM-dd.

date_hour or strict_date_hour

一个包含完整日期和两位数的小时的格式化程序: yyyy-MM-dd'T'HH.

date_hour_minute or strict_date_hour_minute

一个包含完整日期,两位数的天数,两位数的分钟的格式化程序: yyyy-MM-dd'T'HH:mm.

date_hour_minute_second or strict_date_hour_minute_second

一个包含完整日期,两位数的天数,两位数的分钟,两位数的秒数: yyyy-MM-dd'T'HH:mm:ss.

date_hour_minute_second_fraction or strict_date_hour_minute_second_fraction

一个包含完整日期,两位数的小时数,两位数的分钟数,两位数的秒数,三位数的秒的分数:yyyy-MM-dd'T'HH:mm:ss.SSS.

date_hour_minute_second_millis or strict_date_hour_minute_second_millis

一个包含完整日期,两位数的小时,两位数的分钟,两位数的秒数,三位数的秒的分数: yyyy-MM-dd'T'HH:mm:ss.SSS.

date_time or strict_date_time

一个包含完整日期和时间,通过T分割的格式化程序: yyyy-MM-dd'T'HH:mm:ss.SSSZZ.

date_time_no_millis or strict_date_time_no_millis

一个包含完整日期和时间且没有毫秒的,通过T分割的格式化程序: yyyy-MM-dd'T'HH:mm:ssZZ.

hour or strict_hour

一个两位数的小时数的格式化程序: HH

hour_minute or strict_hour_minute

一个两位数的小时数和两位数的分钟数:HH:mm.

hour_minute_second or strict_hour_minute_second

一个两位数的小时数,两位数的分钟数和两位数的秒数:HH:mm:ss.

hour_minute_second_fraction or strict_hour_minute_second_fraction

一个两位数的小时数,两位数的分钟数,两位数的秒数,三位数的秒的分数:HH:mm:ss.SSS.

hour_minute_second_millis or strict_hour_minute_second_millis

一个两位数的小时数,两位数的分钟数,两位数的秒数,三位数的秒的分数: HH:mm:ss.SSS.

ordinal_date or strict_ordinal_date

一个完整日期的格式化程序,使用四位数的年数和三位数年的天数:yyyy-DDD.

ordinal_date_time or strict_ordinal_date_time

一个完整ordinal 日期和时间的格式化程序,使用四位数的年数和三位数的天数:yyyy-DDD'T'HH:mm:ss.SSSZZ.

ordinal_date_time_no_millis or strict_ordinal_date_time_no_millis

一个完整日期和时间没有毫秒的格式化程序,使用四位数的年份和三位数的年的天数: yyyy-DDD'T'HH:mm:ssZZ.

time or strict_time

一个两位数的天数,两位数的小时,两位数的秒,三位数的秒的分数,以及时间偏移量:HH:mm:ss.SSSZZ.

time_no_millis or strict_time_no_millis

一个两位数的小时,两位数的分钟,两位数的秒以及时间偏移量:HH:mm:ssZZ.

t_time or strict_t_time

一个两位数的小时,两位数的分钟,两位数的秒,三位数的秒的分数以及以T为前缀的时间偏移量: 'T'HH:mm:ss.SSSZZ.

t_time_no_millis or strict_t_time_no_millis

一个两位数的小时,两位数的分钟,两位数的秒以及以T为前缀的时间偏移量:'T'HH:mm:ssZZ.

week_date or strict_week_date

一个完整日其的格式化程序,四位数的weekyear,两位数的周数,一位数的天数: xxxx-'W'ww-e.

week_date_time or strict_week_date_time

一个包含完整weekyear 日期和时间的格式化程序,通过T进行分割:xxxx-'W'ww-e'T'HH:mm:ss.SSSZZ.

week_date_time_no_millis or strict_week_date_time_no_millis

一个包含完整 weekyear 日期和时间没有毫秒,以T分割的格式化程序: xxxx-'W'ww-e'T'HH:mm:ssZZ.

weekyear or strict_weekyear

一个四位数的 weekyear 的格式化程序:xxxx

weekyear_week or strict_weekyear_week

一个四位数的 weekyear 和两位数的周数:xxxx-'W'ww.

weekyear_week_day or strict_weekyear_week_day

一个四位数的weekyear 两位数的周数,一位数的天数: xxxx-'W'ww-e.

year or strict_year

一个四位数年份的格式化程序:yyyy.

year_month or strict_year_month

一个四位数年份和两位数月份的格式化程序: yyyy-MM.

year_month_day or strict_year_month_day

一个四位数的年份和两位数的月份,两位数的天数的格式化程序:yyyy-MM-dd.

支持完全可定制的日期格式,这些语法.

.basic_date

PUT mapping API
in the Joda docs
date_optional_time or strict_date_optional_time
Full details here