elasticsearch - 在一个索引中通过 1-N 个相关数据的多个字段进行弹性搜索
问题描述
我已经被这个问题困扰了几天,反复阅读 Elastic 文档无济于事。我希望有人能以正确的方式推动我。
假设有两种类型的数据 - 父母和孩子,它们具有 1-N 关系。我使用自定义type
字段将它们存储在同一个索引中。他们有一些共同的领域和一些不同的领域。举一个具体的例子,索引和一些输入数据可能看起来像:
PUT /myindex
{
"mappings":
{
"properties": {
"type": {"type": "keyword"},
"fileid" : {"type": "keyword"},
"dirid": {"type": "keyword"},
"filename": {"type": "text"},
"fileauthor": {"type": "text"},
"dirpath": {"type": "text"}
}
}
}
PUT /myindex/_doc/1
{
"type": "dir",
"dirid": 1,
"dirpath": "/home/jd/"
}
PUT /myindex/_doc/2
{
"type": "dir",
"dirid": 2,
"dirpath": "/home/jd/Documents/CV/"
}
PUT /myindex/_doc/3
{
"type": "file",
"dirid": 2,
"fileid": 1,
"filename": "My-Resume.pdf",
"fileauthor": "John Doe"
}
PUT /myindex/_doc/4
{
"type": "file",
"dirid": 1,
"fileid": 2,
"filename": "Some-CV.pdf",
"fileauthor": "John Doe"
}
PUT /myindex/_doc/5
{
"type": "file",
"dirid": 1,
"fileid": 3,
"filename": "book.pdf",
"fileauthor": "John Doe"
}
现在我想使用相当复杂的(多词)查询来搜索文本字段,例如John Doe CV
. 对于个人type="dir"
或type="file"
它很简单(查询将返回带有 的文档_id=4
),但我也想获得“混合”结果,其中部分查询包含在父特定字段中,其余部分包含在子特定字段中。在我的示例数据和查询中,我希望它也返回_id=3
,因为作者是John Doe
并且 parentdirpath
包含关键字CV
。
我很高兴得到父母,这足以满足我的需要。(我确实更希望得到父母,但这是我目前遇到的问题之上的事情。)
不知何故,我还没有找到一种方法来做到这一点。我知道这种join
类型,但这似乎没有帮助,相反。随着以前推荐的做法被弃用,许多建议、SO 问题和文档项目都已过时。
当然,我可以用所有数据填充每个条目(每个条目type="file"
只会复制父级的dirpath
值),但这违背了我对内存和空间最佳使用的所有看法。
请问有谁知道在哪里可以看的更远吗?非常感谢。
解决方案
推荐阅读
- java - AssertJ 将提取的字段转换为 Map
- r - R问题:如何计算曲线下面积相对于增加?
- environment-variables - 想知道如何让我的 ENV 变量进入主管
- php - Nginx 不执行 php
- c# - Vuforia Extended Tracking - 是否能够让整个场景环顾四周,还是仅适用于一个对象?
- nlp - huggingface pytorch-transformers:如何用某些值初始化嵌入?
- angular - 如何在角度剑道网格中以编程方式设置当前页面?
- javascript - 如何在输入值更改时始终关注样式化组件输入组件
- mysql - SQL:使用同一张表的结果更新多行
- r - 在记录中读取带有回车符的 fwf