elasticsearch - 对 has_parent 嵌套内部命中的 ElasticSearch 内部命中
问题描述
我已经搜索过这个并且没有找到任何说明这是否支持的内容。根据弹性文档:
“可以通过在嵌套、has_child 或 has_parent 查询和过滤器上定义 inner_hits 定义来使用内部命中。”
我想在 has_parent 嵌套对象上使用 inner_hits。我已经尝试过,如下例所示。有谁知道这是否可能?
示例场景(为了这篇文章的目的,我已经简化了数据和属性)
我们将任务标题和描述翻译存储为父任务中的嵌套对象。每个嵌套标题都有一个 iso 代码和一个翻译的标题和描述。在某些情况下,我们将子任务分发给成千上万的用户,因此将标题/描述复制到每个子对象中是没有意义的。
父任务示例
{
"_id": "parenttask_177448",
"startDate": "2020-05-01T00:00:00",
"endDate": "2020-05-05T00:00:00",
"type": "task",
"taskjoin" : "parenttask",
"priorityId": 1,
"translations": [
{
"title": "This is a test task",
"description": "test",
"localeIsoCode": [
"en-US"
]
},
{
"description": "tester",
"title": "Ceci est une tâche de test",
"localeIsoCode": [
"fr-FR"
]
}
]
}
子任务示例
{
"_id": "childtask_12345",
"taskSubType": "distributed",
"subtasks": [],
"startDate": "2020-03-19T00:00:00",
"endDate": "2020-03-19T00:00:00",
"taskJoinField": {
"name": "childtask",
"parent": "parenttask_177448"
},
"assignedUserId": 12345,
"assignedUserName": "Bob Jones"
}
我正在运行的查询的相关部分不会返回任何内部命中结果
{
"has_parent": {
"ignore_unmapped": true,
"parent_type": "parenttask",
"query": {
"nested": {
"ignore_unmapped": true,
"inner_hits": {
"name": "innerhits_task",
"_source": {
"includes": [
"title"
]
}
},
"path": "translations",
"query": {
"term": {
"translations.localeIsoCode.keyword": {
"value": "fr-FR"
}
}
},
"boost": 1.1,
"_name": "nested_isocode"
}
},
"score": true,
"boost": 1.1,
"_name": "parent_isocode"
}
}
相关映射
{
"thinktime_dev_7003_tasks": {
"mappings": {
"properties": {
"assignedUserId": {
"type": "long"
},
"assignedUserName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"taskJoinField": {
"type": "join",
"eager_global_ordinals": true,
"relations": {
"parenttask": "childtask"
}
},
"localeIsoCode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"locationId": {
"type": "long"
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"translations": {
"type": "nested",
"properties": {
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"image": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"isPrimary": {
"type": "long"
},
"localeIsoCode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
我从子任务中得到结果,但没有内部匹配。如果我将内部点击移动到 has_parent,我会取回所有翻译。
我的问题是在 Elastic 中是否可以进行父嵌套内部点击?我很惊讶在互联网上没有找到其他人尝试这样做或示例。这似乎是一个非常常见的用例。
谢谢你的帮助。
解决方案
推荐阅读
- java - 创建自定义 gradle 任务以获取 mysql 模式
- c - 有没有办法让正在运行的程序在 txt 文件上写入
- java - 我有一些模型我不想手动或自动插入 @Id 我只想从 insert 中导入它?爪哇
- java - 仅 Firebase 实时数据库 DataSnapshot 读取子项中的最后一个值
- mysql - 有没有办法提高 Docker 中 MySql 的性能?
- rabbitmq - RabbitMQ:“message-ttl”和“过期”之间的区别
- php - 在属性注释中使用模型的问题。应该是模型而不是数组
- javascript - 如何简化具有许多条件的 IF 语句
- ansible - Ansible:找不到动态库存模块错误
- swift - 如何检查泛型类型可以快速转换为字符串