[英]double nested elasticsearch query does not work for term clause
I am trying to run ES query on double nested document.我正在尝试在双嵌套文档上运行 ES 查询。 Term query inside the nested query does not seem to work.嵌套查询中的术语查询似乎不起作用。 If i replace the below term query with terms query it works.如果我用术语查询替换下面的术语查询,它就可以工作。 I am posting both mapping and query for your reference.我发布了映射和查询供您参考。 Am i doing anything wrong?我做错什么了吗? I am using ES version 6.4.我正在使用 ES 版本 6.4。 Basically i want to an AND condition on the "bio.mut.type" field and return the docs accordingly.基本上我想在“bio.mut.type”字段上设置一个 AND 条件并相应地返回文档。
Mapping:映射:
{
"assoc": {
"date_detection": true,
"properties": {
"bio": {
"type": "nested",
"properties": {
"node": {
"type": "keyword",
"index": "true"
},
"mut": {
"type": "nested",
"properties": {
"biomarkerType": {
"type": "keyword"
},
"createdBy": {
"type": "keyword"
},
"creationDate": {
"type": "date"
},
"domain": {
"type": "keyword"
},
"id": {
"type": "long"
},
"node": {
"type": "keyword"
},
"status": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"updateDate": {
"type": "date"
},
"updatedBy": {
"type": "keyword"
}
}
}
}
}
},
"version": {
"type": "keyword"
},
"domain": {
"type": "keyword"
}
}
}
QUERY:询问:
{
"bool" : {
"must" : [
{
"nested" : {
"query" : {
"terms" : {
"bio.node" : [
"X"
],
"boost" : 1.0
}
},
"path" : "bio",
"ignore_unmapped" : false,
"score_mode" : "none",
"boost" : 1.0
}
},
{
"nested" : {
"query" : {
"nested" : {
"query" : {
"bool" : {
"must" : [
{
"term" : {
"bio.mut.type" : {
"value" : "M",
"boost" : 1.0
}
}
},
{
"term" : {
"bio.mut.type" : {
"value" : "F",
"boost" : 1.0
}
}
},
{
"term" : {
"bio.mut.type" : {
"value" : "C",
"boost" : 1.0
}
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"path" : "bio.mut",
"ignore_unmapped" : false,
"score_mode" : "none",
"boost" : 1.0
}
},
"path" : "bio",
"ignore_unmapped" : false,
"score_mode" : "none",
"boost" : 1.0
}
},
{
"terms" : {
"domain" : [
"X"
],
"boost" : 1.0
}
}
],
"must_not" : [
{
"terms" : {
"status" : [
"Deleted"
],
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
Sample Document:样本文件:
{
"_index": "XXX",
"_type": "XXX",
"_id": "3",
"_score": 1.0,
"_source": {
"bio": [{
"mut": [{
"id": 3,
"type": "M"
},
{
"id": 4,
"type": "F"
},
{
"id": 5,
"type": "C"
}
]
}]
}
}
Ok, so you're trying to match separate nested documents, ie return the top-level document that contains different nested documents that all match the nested queries.好的,所以您正在尝试匹配单独的嵌套文档,即返回包含所有匹配嵌套查询的不同嵌套文档的顶级文档。
Replace the second top-level must
element by the following one:将第二个顶级must
元素替换为以下元素:
{
"nested": {
"query": {
"bool": {
"must": [
{
"nested": {
"query": {
"term": {
"bio.mut.type": {
"value": "M",
"boost": 1
}
}
},
"path": "bio.mut",
"ignore_unmapped": false,
"score_mode": "none",
"boost": 1
}
},
{
"nested": {
"query": {
"term": {
"bio.mut.type": {
"value": "F",
"boost": 1
}
}
},
"path": "bio.mut",
"ignore_unmapped": false,
"score_mode": "none",
"boost": 1
}
},
{
"nested": {
"query": {
"term": {
"bio.mut.type": {
"value": "C",
"boost": 1
}
}
},
"path": "bio.mut",
"ignore_unmapped": false,
"score_mode": "none",
"boost": 1
}
}
]
}
},
"path": "bio",
"ignore_unmapped": false,
"score_mode": "none",
"boost": 1
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.