mapping 详解3(Meta-Fields)
文档标识相关元数据字段
_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
字段说明
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)的更多相关文章
- mapping 详解2(field datatypes)
基本类型 1. 字符串 字符串类型被分为两种情况:full-text 和 keywords. full-text 表示字段内容会被分析,而 keywords 表示字段值只能作为一个精确值查询. 参数: ...
- mapping 详解4(mapping setting)
mapping type 映射设置一般发生在: 1. 增加新的 index 的时候,添加 mapping type,对 fields 的映射进行设置 PUT twitter { "mappi ...
- Elasticsearch5.X Mapping详解
0.引言 在关系型数据库如Mysql中,设计库表需要注意的是: 1)需要几个表: 2)每个表有哪些字段: 3)表的主键及外键的设定——便于有效关联. 表的设计遵守范式约束,考虑表的可扩展性,避免开发后 ...
- HTMl中Meta标签详解以及meta property=og标签含义
meta是用来在HTML文档中模拟HTTP协议的响应头报文.META标签是HTML语言HEAD区的一个辅助性标签,它位于HTML文档头部的<HEAD>标记和<TITLE>标记之 ...
- mapping 详解5(dynamic mapping)
概述 在使用 ES 的时,我们不需要事先定义好映射设置就可以直接向索引中导入文档.ES 可以自动实现每个字段的类型检测,并进行 mapping 设置,这个过程就叫动态映射(dynamic mappin ...
- mapping 详解1(mapping type)
映射(mapping) 映射是定义一个文档以及其所包含的字段如何被存储和索引的方法. 例如,用映射来定义以下内容: 哪些 string 类型的 field 应当被当成当成 full-text 字段 哪 ...
- [转]HTMl中Meta标签详解以及meta property=og标签含义
meta是用来在HTML文档中模拟HTTP协议的响应头报文.META标签是HTML语言HEAD区的一个辅助性标签,它位于HTML文档头部的<HEAD>标记和<TITLE>标记之 ...
- jQuery Validate验证框架详解
转自:http://www.cnblogs.com/linjiqin/p/3431835.html jQuery校验官网地址:http://bassistance.de/jquery-plugins/ ...
- 谷歌地图地理解析和反解析geocode.geocoder详解
地址解析就是将地址(如:贵州省贵阳市)转换为地理坐标(如经度:106.71,纬度:26.57)的过程. 地理反解析和上面的过程相反是将地理坐标(如纬度:26.57,经度:106.71)转换为地址(中国 ...
随机推荐
- puppet学习:类与类的依赖关系的问题
今天在部署Zabbix的Proxy时,在负责安装的Exec中去掉了一些无关的Package的依赖,结果,就出现了依赖关系的问题. 在zabbix::install中,我写的是require mysql ...
- LeetCode题解——Longest Substring Without Repeating Characters
题目: 给定一个字符串,返回其中不包含重复字符的最长子串长度. 解法: 维持两个指针,第一个指向子串开始,第二个负责遍历,当遍历到的字符出现在子串内时,应计算当前子串长度,并更新最长值:然后第一个指针 ...
- 【译】 AWK教程指南 10编写可与用户交互的AWK程序
执行awk程序时,awk会自动从文件中读取数据来进行处理,直到文件结束.只要将awk读取数据的来源改成键盘输入,便可设计与awk 交互的程序.本节将提供一个该类程序的范例. 范例:本节将编写一个英语生 ...
- class0513(html)
精通DIV+CSS Meta 1.div span 2.三种样式表 内联样式(行内样式) 嵌入样式 外部样式 就近原则 3.常见样式 复合样式background border css单位 % px ...
- 解决adb问题的方法
The connection to adb is down,and a server error has occured. 在网上找的那个高端方法根本不管用,来,试试我的方法.. 先装个360手机助手 ...
- HW5.32
public class Solution { public static void main(String[] args) { int n1 = (int)(Math.random() * 5 + ...
- 关于JavaScripting API您不知道的5件事
现在,许多 Java 开发人员都喜欢在 Java 平台中使用脚本语言,但是使用编译到 Java 字节码中的动态语言有时是不可行的.在某些情况中,直接编写一个 Java 应用程序的脚本 部分 或者在一个 ...
- PCB编辑快捷键
TAB: 调节属性PgUp: 放大PgDn: 缩小Delete: 删除Ctrl+C: 复制Ctrl+V: 粘贴Ctrl+X: 剪贴Ctrl+Z: 撤销Ctrl+Y: 取消撤销Ctrl+F: 查找Ctr ...
- [Xcode使用 - 1] 自定义代码块引用
Xcode本身带有编码常用的代码块可供使用,如下图 例如 “if” 这个代码块的定义 调用方法 1.可以直接拖放带编辑区 2.使用快捷键,键入 “if”, Xcode就会出现自动完成的 ...
- Java快捷键
Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加)Ctrl+Alt+↑ 复制当前行到上一行(复制增加)Alt+↓ 当 ...