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
  • IP型
  • Token count 令牌计数型
  • token_count参数
  • Percolator 抽取型
  • 专用渗透索引
  • 强制未映射的字段被处理为字符串
  • 限制

Was this helpful?

  1. 3.基础
  2. 3.2.Mapping
  3. 3.2.1.字段的数据类型

3.2.1.4.特定数据类型

分类

数据类型

IP型

ip:描述IPv4 和 IPv6 地址

Completion补全型

completion:提供自动完成的提示

Token count 令牌计数型

token_count:用于统计字符串中的词条数量

mapper-murmur3 型

murmur3:计算哈希值在指数时间和并存储他们在索引中

Attachment 附件型

Percolator 抽取型

接受特定领域查询语言(query-dsl)的查询

IP型

一个ip 字段可以索引/存储IPv4和IPv6地址。

PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "ip_addr": {
          "type": "ip"
        }
      }
    }
  }
}

PUT my_index/my_type/1
{
  "ip_addr": "192.168.1.1"
}

GET my_index/_search
{
  "query": {
    "term": {
      "ip_addr": "192.168.0.0/16"
    }
  }
}

IP数据类型字段的参数

以下是ip字段所接受的参数:

boost

映射字段级查询时间提升。接受浮点数,默认值为1.0

doc_values

该字段是否应该按列的方式存储在磁盘上,以便以后可以用于排序、聚合或脚本编写?接受true(默认)或false。

include_in_all

字段值是否应包含在_all字段中? 接受true或false 。如果index设置为no ,或者如果父object字段将include_in_all,默认设置为false。 否则默认为true 。

index

字段是否参数搜索,参数只接受 true (默认值) 和 false

null_value

接受一个配置格式的IPv4值作为替换任何显式空值的字段。 默认为null,这意味着该字段被视为丢失。

store

字段值是否应与_source字段分开存储和检索。 接受true或false (默认)。

查询IP字段

最常见的查询ip地址的方法是使用CIDR标记:[ip_address]/[prefix_length]. 例如:

GET my_index/_search
{
  "query": {
    "term": {
      "ip_addr": "192.168.0.0/16"
    }
  }
}

或

GET my_index/_search
{
  "query": {
    "term": {
      "ip_addr": "2001:db8::/48"
    }
  }
}

Token count 令牌计数型

类型为token_count的字段是一个接受字符串值的integer字段,对它们进行分析,然后对字符串中的token数进行索引。

例子:

PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "name": { # 1
          "type": "text",
          "fields": { # 2
            "length": {
              "type":     "token_count",
              "analyzer": "standard"
            }
          }
        }
      }
    }
  }
}

PUT my_index/my_type/1
{ "name": "John Smith" }

PUT my_index/my_type/2
{ "name": "Rachel Alice Williams" }

GET my_index/_search
{
  "query": {
    "term": {
      "name.length": 3  # 3
    }
  }
}

name字段是使用默认standard分析器的分析字符串字段。

此查询仅匹配包含Rachel Alice Williams的文档,因为它包含三个token。

在技术上, token_count类型对位置增量进行求和,而不是对token计数。这意味着即使分析仪滤除停止词,它们也包括在计数中。

token_count参数

token_count字段接受以下参数:

映射字段级查询时间提升。接受一个浮点数,默认为1.0 。

该字段是否应该以多列的方式存储在磁盘上,以便以后可以将其用于排序,聚合或脚本化?接受true (默认)或false 。

应该可以搜索该字段吗?接受not_analyzed (默认)和no 。

接受与替换任何显式null值的字段相同type的数值。默认为null ,这意味着该字段被视为丢失。

Percolator 抽取型

包含json对象的任何字段都可以配置为渗滤器字段。渗滤器字段类型没有参数设置。只需配置渗percolator字段类型就足以指示ES将字段视为查询。

如果以下映射配置query字段的percolator字段类型:

{
    "properties": {
        "query": {
            "type": "percolator"
        }
    }
}

那么下面的json代码段可以作为本地查询进行索引:

{
    "query" : {
                "match" : {
                        "field" : "value"
                }
        }
}

此外,索引只能包含多达一个渗滤型字段映射。多个字段将被put索引拒绝并放置映射API。

专用渗透索引

渗滤型查询可以添加到任何索引。而不是向数据所在的索引添加渗出查询,也可以将这些查询添加到专用索引中。这样做的优点在于,这个专用的渗透索引可以有自己的索引设置(例如主分片和副本分片的数量)。如果您选择具有专门的渗透指数,则需要确保来自正常索引的映射也可在渗透指数中使用。否则,渗出查询可能会被错误解析。

强制未映射的字段被处理为字符串

在某些情况下,什么样的渗滤查询已经被注册了是不知道的,如果字段未映射的那些字段被渗透查询所引用,那么将添加渗滤查询失败。这意味着需要更新映射以使该字段具有适当的设置,然后可以添加渗滤查询。但是有时如果所有未映射的字段都被处理,就像这些是默认的字符串字段一样。在这种情况下,可以将index.percolator.map_unmapped_fields_as_string设置设置为true (默认为false ),然后如果在percolator查询中引用的字段不存在,则它将作为默认字符串字段处理,以便添加渗滤查询不会失败。

限制

因为percolate查询一次处理一个文档,它不支持针对子文件,如has_child和has_parent运行的查询和过滤器。

在查询解析过程中有许多通过调用进行获取数据的查询。例如使用terms查询时的术语查询,使用索引脚本时的template查询以及使用预索引形状时的geo_shape 。当这些查询由percolator字段类型索引时,get调用将被执行一次。因此,每次percolator查询评估这些查询时,将使用索引时间获取术语,形状等。如果源索引在索引时更改,需要注意的是要获取这些查询所执行的术语,每次在渗滤器查询在主分片和副本分片上进行索引时都会发生,所以实际索引的术语在分片副本之间可能不同。

Previous3.2.1.3.Geo地理数据类型Next3.2.2.Meta-Fields(元字段)

Last updated 5 years ago

Was this helpful?

查看插件来支持索引附件,如微软Office格式,开放文档格式,EPUB,HTML等附件类型。

name.length字段是一个token_count ,它将在name字段中索引token的数量。

应该用于分析字符串值的 。必须值。为获得最佳性能,请使用不带token过滤器的分析器。

字段值是否应包含在字段中?接受true或false默认为false 。注意:如果为true ,则将字符串值添加到_all,而不是计算的token数量。

字段值是否应与字段分开存储和检索。接受true或false (默认)。

percolator字段类型将json结构解析为本地查询,并存储该查询,以便可以使用它来匹配提供的文档。

在渗滤型查询中引用的字段必须已经存在于与用于渗滤的索引相关联的映射中。为了确保这些字段存在,通过或 API添加或更新映射 。在渗滤型查询中引用的字段可以存在于包含percolator字段类型的任何类型的索引中。

percolate查询
创建索引
放置映射
mapper-attachments
多字段
analyzer
分析器
boost
doc_values
index
include_in_all
_all
null_value
store
_source