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)转换为地址(中国 ...
随机推荐
- 《Nagios系统监控实践》一书出版
本书是我的第一本译著,有此机会实属机缘巧合.虽然使用Nagios只有一年多的时间,但是作为用户,我深感其设计的简洁与高效—没有一丝多余的东西.因为工作的关系,要求对各个领域都有所了解,所以没有仔细地阅 ...
- Inf2Cat, signability test failed.
驱动开发真不是那么好玩的,折腾了几天,排除了几个错误,又有新的错误了. 错误 1 error -2: "Inf2Cat, signability test failed.&quo ...
- java创建对象的四种方式
1.最常见的 new 一个 2使用反射机制创建对象,直接调用非构造函数 Class obj=Class.forName("A"); A a=obj.newInstance(); C ...
- 解决:Eclipse导入工程后全是错误,连基本类型都不识别
当初在大学没时间完成作业时,总是喜欢网上搜一个或者拷贝同学的一个工程过来,导入到Eclipse中却全是红叉,连基本类型都不识别. 当时就纳闷了,难道是天要亡我之心不死?后来慢慢了解了,其实是导入的工程 ...
- 浅谈 Python 的 with 语句
with 语句是在 Python 2.5 版本引入的,从 2.6 版本开始成为缺省的功能.with 语句作为 try/finally 编码范式的一种替代,用于对资源访问进行控制的场合.本章对 with ...
- 分享两个模拟get和post方法的工具类,让应用能够与服务器进行数据交互
很久没有码字了,今天跟大家分享一个模拟get和post方法的工具类,在安卓应用中很多都需要跟服务器进行数据交互,这需要两方面的配合,首先服务器端会给应用提供一些数据交互的接口,可是怎样在应用中去调用呢 ...
- 深度学习-使用cuda加速卷积神经网络-手写数字识别准确率99.7%
源码和运行结果 cuda:https://github.com/zhxfl/CUDA-CNN C语言版本参考自:http://eric-yuan.me/ 针对著名手写数字识别的库mnist,准确率是9 ...
- 让一个WebRole支持多个站点
在参考Configure a Web Role for Multiple Web Sites和Tips for Publishing Multiple Sites in a Web Role两篇文章后 ...
- HW5.32
public class Solution { public static void main(String[] args) { int n1 = (int)(Math.random() * 5 + ...
- HW5.28
public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\n&qu ...