文档标识相关元数据字段

_index

  • 当执行多索引查询时,可能需要添加特定的一些与文档有关联的索引的子句。
  • _index 字段可以用在 term、terms 查询,聚合(aggregations)操作,脚本(script)操作以及用来排序(sort)。
GET index_1,index_2/_search
{
"query": {
"terms": {
"_index": ["index_1", "index_2"]
}
},
"aggs": {
"indices": {
"terms": {
"field": "_index",
"size":
}
}
},
"sort": [
{
"_index": {
"order": "asc"
}
}
],
"script_fields": {
"index_name": {
"script": "doc['_index']"
}
}
}

_index field

_type

  • _type 可以用来让针对具体 type 的搜索更加快。
  • _type 字段可以用在 querys、aggregations、scripts 以及 sorting。
GET my_index/_search/type_*
{
"query": {
"terms": {
"_type": [ "type_1", "type_2" ]
}
},
"aggs": {
"types": {
"terms": {
"field": "_type",
"size":
}
}
},
"sort": [
{
"_type": {
"order": "desc"
}
}
],
"script_fields": {
"type": {
"script": "doc['_type']"
}
}
}

_type field

原始信息相关元数据字段

_source

字段说明

  • _source 字段存放的是文档的原始 JSON 信息
  • _source 字段不被 indexed ,不过被 stored ,所以可以通过 get 或 search 取得该字段的值。

禁用_source字段

  • _source 字段可以在 mapping 设置中禁用
  • 如果禁用 _source 字段将会有一些其它影响,比如:update API 将无法使用等等。
PUT tweets
{
"mappings": {
"tweet": {
"_source": {
"enabled": false
}
}
}
}

enable _source

_source排除特定字段

  • 在 _source 的 mapping 设置中可以通过 includes 和 excludes 参数来包含或排除特定字段
  • 包含或排除的字段,需要以 plain 格式的 field 名称,名称支持通配符。
PUT logs
{
"mappings": {
"event": {
"_source": {
"includes": [
"*.count",
"meta.*"
],
"excludes": [
"meta.description",
"meta.other.*"
]
}
}
}
}

include _source

索引操作相关元数据字段

_all

字段说明

  • _all 字段把其他所有字段的内容存储到一个大的字符串中,不管其它字段是什么数据类型,在 _all 中都被当作字符串处理。
  • 每个 index 只有一个 _all 字段。
  • 该字符串会被 analyzed 和 indexed,但不会 store(存储)。可以被搜索,但无法用来恢复。
  • _all 字段也和普通字符串字段一样可以接收:analyzer、term_vectors、index_options 和 store 等参数。
  • 生成 _all 字段是有资源消耗的,会消耗 CPU 和 disk 存储。
GET my_index/_search
{
"query": {
"match": {
"_all": "john smith 1970"
}
}
}

_all query

_all字段查询

  • query_string 和 simple_query_string 查询操作,默认就是查询 _all 字段,除非自己明确指定。
GET _search
{
"query": {
"query_string": {
"query": "john smith 1970"
}
}
}

_all query_string

禁用_all字段

  • _all 字段可以在 mapping 设置中完全禁用,如果禁用,query_string 和 simple_query_string 查询操作需要指定默认字段才可用。
PUT my_index
{
"mappings": {
"my_type": {
"_all": {
"enabled": false
},
"properties": {
"content": {
"type": "string"
}
}
}
},
"settings": {
"index.query.default_field": "content"
},
}

enable _all

_all排除特定字段

  • 字段通过 mapping 设置可以通过 include_in_all 参数控制该字段否包含在 _all 字段。
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"date": {
"type": "date",
"include_in_all": false
}
}
}
}
}

include_in_all

_all字段存储

  • _all 字段可以通过参数 store 来设置其是否存储。
PUT myindex
{
"mappings": {
"mytype": {
"_all": {
"store": true
}
}
}
}

store _all

_field_names

字段说明

  • _field_names 字段是用来存储文档中所有非 null 字段的字段名称的。
  • 该字段供 existsmissing 查询使用,来查询某个文档中是否包含或不包含某个字段。
GET my_index/_search
{
"query": {
"terms": {
"_field_names": [ "title" ]
}
},
"aggs": {
"Field names": {
"terms": {
"field": "_field_names",
"size":
}
}
},
"script_fields": {
"Field names": {
"script": "doc['_field_names']"
}
}
}

_field_names

路由相关元数据字段

_parent

字段说明

  • 在同一个 index 中,可以通过设置 type 的父子关系来建立文档之间的父子关系。
  • 父子 type 必须是不同的 type。
  • 指定的 parent type 必须要是还不存在的,已存在的 type 不能作为其它 type 的 parent type。
  • 父子关系的 doc 必须被索引到相同的 shard 上,子文档通过参数 parent 参数来作为其 routing 来保证索引到相同分片。
PUT my_index
{
"mappings": {
"my_parent": {},
"my_child": {
"_parent": {
"type": "my_parent"
}
}
}
}

_parent

_routing

  • _routing 字段用来确定文档索引的分片:shared_num = hash(routing) % num_primary_shards
  • 默认的 _routing 是文档的 _id 或 _parent 的 ID。
  • 通过 routing 参数可以自定义 _routing 的值。
GET my_index/_search
{
"query": {
"terms": {
"_routing": [ "user1" ]
}
},
"aggs": {
"Routing values": {
"terms": {
"field": "_routing",
"size":
}
}
},
"sort": [
{
"_routing": {
"order": "desc"
}
}
],
"script_fields": {
"Routing value": {
"script": "doc['_routing']"
}
}
}

_routing

mapping 详解3(Meta-Fields)的更多相关文章

  1. mapping 详解2(field datatypes)

    基本类型 1. 字符串 字符串类型被分为两种情况:full-text 和 keywords. full-text 表示字段内容会被分析,而 keywords 表示字段值只能作为一个精确值查询. 参数: ...

  2. mapping 详解4(mapping setting)

    mapping type 映射设置一般发生在: 1. 增加新的 index 的时候,添加 mapping type,对 fields 的映射进行设置 PUT twitter { "mappi ...

  3. Elasticsearch5.X Mapping详解

    0.引言 在关系型数据库如Mysql中,设计库表需要注意的是: 1)需要几个表: 2)每个表有哪些字段: 3)表的主键及外键的设定——便于有效关联. 表的设计遵守范式约束,考虑表的可扩展性,避免开发后 ...

  4. HTMl中Meta标签详解以及meta property=og标签含义

    meta是用来在HTML文档中模拟HTTP协议的响应头报文.META标签是HTML语言HEAD区的一个辅助性标签,它位于HTML文档头部的<HEAD>标记和<TITLE>标记之 ...

  5. mapping 详解5(dynamic mapping)

    概述 在使用 ES 的时,我们不需要事先定义好映射设置就可以直接向索引中导入文档.ES 可以自动实现每个字段的类型检测,并进行 mapping 设置,这个过程就叫动态映射(dynamic mappin ...

  6. mapping 详解1(mapping type)

    映射(mapping) 映射是定义一个文档以及其所包含的字段如何被存储和索引的方法. 例如,用映射来定义以下内容: 哪些 string 类型的 field 应当被当成当成 full-text 字段 哪 ...

  7. [转]HTMl中Meta标签详解以及meta property=og标签含义

    meta是用来在HTML文档中模拟HTTP协议的响应头报文.META标签是HTML语言HEAD区的一个辅助性标签,它位于HTML文档头部的<HEAD>标记和<TITLE>标记之 ...

  8. jQuery Validate验证框架详解

    转自:http://www.cnblogs.com/linjiqin/p/3431835.html jQuery校验官网地址:http://bassistance.de/jquery-plugins/ ...

  9. 谷歌地图地理解析和反解析geocode.geocoder详解

    地址解析就是将地址(如:贵州省贵阳市)转换为地理坐标(如经度:106.71,纬度:26.57)的过程. 地理反解析和上面的过程相反是将地理坐标(如纬度:26.57,经度:106.71)转换为地址(中国 ...

随机推荐

  1. POJ 3630- Phone List(Trie)

    题意:给一组串,是否存在一个串是另一个的前缀. 分析:val[N]保存树节点上是否组成一个串 #include <map> #include <set> #include &l ...

  2. RhinoMocks简单范例

    using System; namespace MockTest { public interface IBBB { int Number { get; } int Compute(int j); i ...

  3. ADB 远程无线调试

    由于自己购买的x4412 Android开发板存在一个问题,是无法同时链接USB线,和插入无线网卡.只能使用其中一个功能 需要复现一个DRM在线下载的功能,同时需要抓起一些日志信息,此处就想到了使用 ...

  4. NOIP2005 过河

    过河 (river.pas/c/cpp) [问题描述] 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正 ...

  5. CodeForces 149D Coloring Brackets 区间DP

    http://codeforces.com/problemset/problem/149/D 题意: 给一个给定括号序列,给该括号上色,上色有三个要求 1.只有三种上色方案,不上色,上红色,上蓝色 2 ...

  6. (Trie) uvalive 3942 Remember the word

    题意:告诉你一个母串和子串,能用多少种不同的方案组合出母串. 思路:字典树(显然)+DP DP: dp[i]+=dp[j+1]  i<=j<=m-1,且i到j的字符串能在字典树中找到.也就 ...

  7. MFC中Listbox控件的简单使用

    MFC中listbox控件是为了显示一系列的文本,每个文本占一行.   Listbox控件可以设置属性为: LBS_CHILD   :(默认)子窗口 LBS_Visible :(默认)可视 LBS_M ...

  8. 清空具有外键约束的表时报ERROR 1701(42000)的解决办法

    ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (`furion`.`tbl_fr ...

  9. poj2152 Fire

    好难啊,我弱爆了. 题解看陈启峰的论文... /** * Problem:POJ2152 * Author:Shun Yao * Time:2013.9.2 * Result:Accepted * M ...

  10. 【tyvj1952】easy

    AK大神又AK了!!! orzorzorz 题意: 给出一个字符串由'x'.'o'.'?' '?'有一半的几率为'x' 一半几率为'o' 得分为所有连续的'o'的个数的平方和 如ooxooo 得分为2 ...