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)转换为地址(中国 ...
随机推荐
- init进程学习
linux的init进程 一个在线编辑markdown文档的编辑器,是内核启动的第一个进程,init进程有很多重要的任务,它的pit 为1,在linux shell中使用pstree命令可以看到它为其 ...
- C++ 继承之虚继承与普通继承的内存分布
仅供互相学习,请勿喷,有观点欢迎指出~ class A { virtual void aa(){}; }; class B : public virtual A { ]; //加入一个变量是为了看清楚 ...
- 微软Azure云主机及blob存储的网络性能测试
http://www.cnblogs.com/sennly/p/4137024.html 微软Azure云主机及blob存储的网络性能测试 1. 测试目的 本次测试的目的在于对微软Azure的云主机. ...
- MySQL命令使用手记
1.登陆 >mysql -u root -p,root没密码按回车. 2.创建数据库 >create database XXX; 3.创建用户 >inse ...
- eclipse下使用tomcat启动maven项目
最近学习使用maven,建立了一个maven项目使用eclipse下tomcat启动时报错: 严重: ContainerBase.addChild: start: org.apache.catalin ...
- 用UGN3503霍尔器件制作的数字指南针_电路图
本文介绍了用两个UGN3503型霍尔器件设计制作的数字指南针的设计目的.系统结构和工作原理,以及各主要器件的使用方法.本系统包括UGN3503型霍尔器件.TLC0832 A/D转换器.单片机控制.液晶 ...
- 第一次见4.3K电阻
今天焊RC522的实验板,接收电阻买的是5.1K,焊接时发现丝层写的是432,阻为4.26K.理论值应该是4.3K
- C++学习笔记(三):数组
数组声明时必须指定该数组的长度: ]; 这个时候已经分配了内存,但没有初始化,所以具体的值是不确定的: 初始化: ] = {, , }; ] = {};//指定第一个数字为1,后面的使用0填充: ] ...
- Unable to resolve module LinkedStateMixin
由于前面reactive文件夹的删除,导致运行程序的时候出现Unable to resolve module LinkedStateMixin 的错误. 搞了好久都没办法解决,看来不深入其中,无法解决 ...
- Php AES加密、解密与Java互操作的问题
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...