elasticsearch 基础 —— Inner hits
Inner hits
The parent-join and nested 功能允许返回具有不同范围匹配的文档。在父/子案例中,基于子文档中的匹配返回父文档,或者基于父文档中的匹配返回子文档。在嵌套的情况下,基于嵌套内部对象中的匹配返回文档。 在这两种情况下,隐藏了导致文档返回的不同范围中的实际匹配。在许多情况下,知道哪些内部嵌套对象(在嵌套的情况下)或子/父文档(在父/子的情况下)返回某些信息非常有用。内部命中功能可用于此目的。此功能会在搜索响应中返回每次搜索命中,这会导致搜索匹配在不同范围内匹配。
可以通过在nested,has_child或has_parent查询和过滤器上定义inner_hits定义来使用内部命中。结构如下所示:
"<query>" : {
"inner_hits" : {
<inner_hits_options>
}
}
如果inner_hits在支持它的查询上定义,则每个搜索命中将包含inner_hits具有以下结构的json对象:
"hits": [
{
"_index": ...,
"_type": ...,
"_id": ...,
"inner_hits": {
"<inner_hits_name>": {
"hits": {
"total": ...,
"hits": [
{
"_type": ...,
"_id": ...,
...
},
...
]
}
}
},
...
},
...
]
选项
内部命中支持以下选项:
|
|
|
|
|
每个返回的最大匹配数 |
|
|
应如何对内部命中进行排序 |
|
|
用于响应中特定内部命中定义的名称。在单个搜索请求中定义了多个内部命中时很有用。默认值取决于定义内部命中的查询。对于 |
内部命中还支持以下每个文档功能:
Nested inner hits
嵌套的inner_hits可用于包括嵌套的内部对象作为搜索命中的内部命中。
PUT test
{
"mappings": {
"_doc": {
"properties": {
"comments": {
"type": "nested"
}
}
}
}
}
PUT test/_doc/1?refresh
{
"title": "Test title",
"comments": [
{
"author": "kimchy",
"number": 1
},
{
"author": "nik9000",
"number": 2
}
]
}
POST test/_search
{
"query": {
"nested": {
"path": "comments",
"query": {
"match": {"comments.number" : 2}
},
"inner_hits": {} ①
}
}
}
|
|
嵌套查询中的内部命中定义。没有其他选择需要定义。 |
可以从上述搜索请求生成的响应代码段示例:
{
...,
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": ...,
"inner_hits": {
"comments": { ①
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "1",
"_nested": {
"field": "comments",
"offset": 1
},
"_score": 1.0,
"_source": { ②
"author": "nik9000",
"number": 2
}
}
]
}
}
}
}
]
}
}
|
|
搜索请求中内部匹配定义中使用的名称。可以通过该 |
在上述示例中,嵌套元数据是至关重要的,因为它定义了从内部嵌套对象中产生的内部嵌套对象。字段定义嵌套命中的对象数组字段和相对于其在源中的位置的偏移量。由于排序和评分,inner_hits中命中对象的实际位置通常与定义嵌套内部对象的位置不同。
默认情况下,在内命中命中对象也返回了_source,但这可以被改变。通过源过滤功能,可以返回或禁用源的一部分。如果在嵌套级别上定义了存储字段,那么这些字段也可以通过字段特性返回。
一个重要的默认值是,在内射命中中的命中返回的_source与嵌套的元数据相对应。因此,在上面的示例中,每次嵌套命中只返回注释部分,而不返回包含注释的顶级文档的整个源。
Hierarchical levels of nested object fields and inner hits.
如果映射具有多级分层嵌套对象字段,则可以通过点标记路径访问每个级别。例如,如果存在comments包含votes嵌套字段的嵌套字段,并且应该直接返回带有根命中的投票,则可以定义以下路径:
PUT test
{
"mappings": {
"_doc": {
"properties": {
"comments": {
"type": "nested",
"properties": {
"votes": {
"type": "nested"
}
}
}
}
}
}
}
PUT test/_doc/1?refresh
{
"title": "Test title",
"comments": [
{
"author": "kimchy",
"text": "comment text",
"votes": []
},
{
"author": "nik9000",
"text": "words words words",
"votes": [
{"value": 1 , "voter": "kimchy"},
{"value": -1, "voter": "other"}
]
}
]
}
POST test/_search
{
"query": {
"nested": {
"path": "comments.votes",
"query": {
"match": {
"comments.votes.voter": "kimchy"
}
},
"inner_hits" : {}
}
}
}
看起来像是这样的:
{
...,
"hits": {
"total": 1,
"max_score": 0.6931472,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "1",
"_score": 0.6931472,
"_source": ...,
"inner_hits": {
"comments.votes": {
"hits": {
"total": 1,
"max_score": 0.6931472,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "1",
"_nested": {
"field": "comments",
"offset": 1,
"_nested": {
"field": "votes",
"offset": 0
}
},
"_score": 0.6931472,
"_source": {
"value": 1,
"voter": "kimchy"
}
}
]
}
}
}
}
]
}
}
仅对嵌套的内部命中支持此间接引用。
Parent/child inner hits
父/子inner_hits可以用于包括父或子:
PUT test
{
"mappings": {
"_doc": {
"properties": {
"my_join_field": {
"type": "join",
"relations": {
"my_parent": "my_child"
}
}
}
}
}
}
PUT test/_doc/1?refresh
{
"number": 1,
"my_join_field": "my_parent"
}
PUT test/_doc/2?routing=1&refresh
{
"number": 1,
"my_join_field": {
"name": "my_child",
"parent": "1"
}
}
POST test/_search
{
"query": {
"has_child": {
"type": "my_child",
"query": {
"match": {
"number": 1
}
},
"inner_hits": {}
}
}
}
|
|
内部命中定义,如嵌套示例中所示。 |
{
...,
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"number": 1,
"my_join_field": "my_parent"
},
"inner_hits": {
"my_child": {
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "2",
"_score": 1.0,
"_routing": "1",
"_source": {
"number": 1,
"my_join_field": {
"name": "my_child",
"parent": "1"
}
}
}
]
}
}
}
}
]
}
}
elasticsearch 基础 —— Inner hits的更多相关文章
- ELK(elasticsearch+kibana+logstash)搜索引擎(二): elasticsearch基础教程
1.elasticsearch的结构 首先elasticsearch目前的结构为 /index/type/id id对应的就是存储的文档ID,elasticsearch一般将数据以JSON格式存储. ...
- Elasticsearch 基础入门
原文地址:Elasticsearch 基础入门 博客地址:http://www.extlight.com 一.什么是 ElasticSearch ElasticSearch是一个基于 Lucene 的 ...
- ElasticSearch 基础 1
ElasticSearch 基础=============================== 索引创建 ========================== 1. RESTFUL APIAPI 基本 ...
- Elasticsearch基础但非常有用的功能之二:模板
文章转载自: https://mp.weixin.qq.com/s?__biz=MzI2NDY1MTA3OQ==&mid=2247484584&idx=1&sn=accfb65 ...
- 最完整的Elasticsearch 基础教程
翻译:潘飞(tinylambda@gmail.com) 基础概念 Elasticsearch有几个核心概念.从一开始理解这些概念会对整个学习过程有莫大的帮助. 接近实时(NRT) Ela ...
- ELK 之一:ElasticSearch 基础和集群搭建
一:需求及基础: 场景: 1.开发人员不能登录线上服务器查看详细日志 2.各个系统都有日志,日志数据分散难以查找 3.日志数据量大,查询速度慢,或者数据不够实时 4.一个调用会涉及到多个系统,难以在这 ...
- Elasticsearch基础教程
Reference: http://blog.csdn.net/cnweike/article/details/33736429 基础概念 Elasticsearch有几个核心概念.从一开始理解这些概 ...
- elasticsearch 基础知识汇总
索引分片: 从策略层面,控制分片分配的选择 磁盘限额 为了保护节点数据安全,ES 会定时(cluster.info.update.interval,默认 30 秒)检查一下各节点的数据目录磁盘使用情况 ...
- 搜索引擎框架之ElasticSearch基础详解(非原创)
文章大纲 一.搜索引擎框架基础介绍二.ElasticSearch的简介三.ElasticSearch安装(Windows版本)四.ElasticSearch操作客户端工具--Kibana五.ES的常用 ...
随机推荐
- [sqlmap 源码阅读] heuristicCheckSqlInjection 探索式注入
上面是探索式注入时大致调用过程,注入 PAYLOAD 1.)("'(.((. , 数据库报错,通过报错信息获取网站数据库类型(kb.dbms),并将保存报错(lasterrorpage). ...
- No Spring Session store is configured: set the 'spring.session.store-type'
发现session store type使用来存放session的存储方式,目前Spring boot中只支持Redis方式. 由于本应用暂无需将session放入redis的需求,故这里就可以将se ...
- HY 的惩罚 (Trie 树,博弈论)
[问题描述] hy 抄题解又被老师抓住了,现在老师把他叫到了办公室. 老师要 hy 和他玩一个游 戏.如果 hy 输了,老师就要把他开除信息组; 游戏分为 k 轮.在游戏开始之前,老师会将 n 个由英 ...
- python读取数据
#读取一行数据,去掉头尾空格 line = sys.stdin.readline().strip() #line类型为字符串 #字符串变成列表 line = sys.stdin.readline(). ...
- 李满春与WebGIS
李满春 ,男,1964年6月生,博士,教授,博导.现任南京大学科技处处长.地理信息科学系主任(兼).地理信息系统与遥感研究所所长(兼).国际地球系统科学研究所(学科特区)常务副所长(兼).第六届高等学 ...
- Windows 下开启FTP服务并创建FTP用户
Windows 下开启FTP服务,并创建用户 此教程教你怎么开启 Windows 的 FTP 服务,并创建用于登入 FTP 的用户.教程用到的操作系统是 Windows 7. 一.创建用于登入 FTP ...
- QQ空间分享网址
现在大部分网站都在每个界面设计了分享这个功能,但还是有的网页没有(比如 B 站只能分享具体的视频).在原来的 QQ 空间分享的地方已经找不到法自己创建分享.上网一搜有分享的接口,可这个接口是给开发者用 ...
- Linux 软件安装到哪里合适,目录详解
文章来源: https://blog.csdn.net/qq_22771739/article/details/83933473 Linux 的软件安装目录是也是有讲究的,理解这一点,在对系统管理是有 ...
- 002-Visio绘制时序图
一.概述 1.1.什么时候使用 当编码的时候,知道有的用例的业务逻辑按照比较确定的时间先后顺序进行展开.这时候,我们就需要知道我们设计的系统中的不同类之间传递消息(可以认为是不同对象函数间的调用)要按 ...
- 【转载】Spring Boot:常用属性汇总
附录A.常用应用程序属性 摘自:https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-pr ...