我需要比较同一文档中的2个字段,其中实际值无关紧要.考虑这个文件:
_source: {
id: 123,
primary_content_type_id: 12,
content: [
{
id: 4,
content_type_id: 1
assigned: true
},
{
id: 5,
content_type_id: 12,
assigned: false
}
]
}
Run Code Online (Sandbox Code Playgroud)
我需要找到未分配主要内容的所有文档.我找不到将primary_content_type_id与嵌套的content.content_type_id进行比较的方法,以确保它们是相同的值.这是我尝试使用脚本.我不认为我理解脚本,但这可能是解决此问题的方法:
{
"filter": {
"nested": {
"path": "content",
"filter": {
"bool": {
"must": [
{
"term": {
"content.assigned": false
}
},
{
"script": {
"script": "primary_content_type_id==content.content_type_id"
}
}
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,它工作正常,如果我删除了过滤器的脚本部分,并与其他术语过滤器更换,其中content_type_id = 12也添加了另一个筛选其中primary_content_id = 12.问题是我不知道(对我的用例来说也不重要)什么是primary_content_type_id或者content.content_type_id是什么的价值.重要的是分配对于content_type_id匹配的内容是错误的primary_content_type_id.
弹性搜索可以检查吗?