我正在尝试在ES-2.3.4上执行以下查询。如果最后删除内联脚本,则查询按预期工作。但是如果我包含脚本,那么查询应该返回结果,但事实并非如此。这是一个时髦的剧本。其中“bio”是嵌套对象。任何人都可以验证查询并建议我是否需要进行任何更改。
{
"bool" : {
"must" : [ {
"nested" : {
"query" : {
"term" : {
"bio.cl" : "Position"
}
},
"path" : "bio"
}
}, {
"nested" : {
"query" : {
"terms" : {
"bio.type" : [ "SV" ]
}
},
"path" : "bio"
}
}, {
"nested" : {
"query" : {
"terms" : {
"bio.node" : [ "XX" ]
}
},
"path" : "bio"
}
}, {
"terms" : {
"domain" : [ "YY" ]
}
} ],
"filter" : [ {
"nested" : {
"query" : {
"term" : {
"bio.chromo" : 1
}
},
"path" : "bio"
}
}, {
"nested" : {
"query" : {
"range" : {
"bio.start" : {
"from" : null,
"to" : 1000140.0,
"include_lower" : true,
"include_upper" : true
}
}
},
"path" : "bio"
}
}, {
"nested" : {
"query" : {
"range" : {
"bio.stop" : {
"from" : 1000861.0,
"to" : null,
"include_lower" : true,
"include_upper" : true
}
}
},
"path" : "bio"
}
}, {
"script" : {
"script" : {
"inline" : "percent <= ([stop,_source.bio.stop.value].min() - [start,_source.bio.start.value].max())/[length,_source.bio.stop.value-_source.bio.start.value+1].max()",
"params" : {
"stop" : 1001100,
"start" : 999901,
"length" : 1200,
"percent" : 0.8
}
}
}
} ]
}
}
映射:
"mappings": {
"XX": {
"properties": {
"bio": {
"type": "nested",
"properties": {
"alt": {
"type": "string",
"index": "not_analyzed"
},
"ann": {
"type": "string",
"index": "not_analyzed"
},
"chromo": {
"type": "string",
"index": "not_analyzed"
},
"cod": {
"type": "string"
},
"conseq": {
"type": "string",
"index": "not_analyzed"
},
"contri": {
"type": "string",
"index": "not_analyzed"
},
"created": {
"type": "string",
"index": "not_analyzed"
},
"createdDate": {
"type": "date",
"format": "strict_date_optional_time"
},
"domain": {
"type": "string",
"index": "not_analyzed"
}"id": {
"type": "long"
},
"name": {
"type": "string",
"index": "not_analyzed"
},
"node": {
"type": "string",
"index": "not_analyzed"
},
"position": {
"type": "string",
"index": "not_analyzed"
},
"level": {
"type": "string",
"index": "not_analyzed"
},
"start": {
"type": "long"
},
"stop": {
"type": "long"
}
}
}
}
}
}
示例文件:
_source" : {
"id" : 25,
"bio" : [ {
"creation" : "2018-03-05T20:26:46.466Z",
"updateDate" : "2018-03-05T20:26:46.466Z",
"createdBy" : "XX",
"type" : "SV",
"creationDate" : "2018-03-05T20:26:46.472Z",
"updateDate" : "2018-03-05T20:26:46.521Z",
"createdBy" : "XX",
"updatedBy" : "XX",
"domain" : "YY",
"node" : "XX",
"ann" : "1.6",
"gen" : "37",
"level" : "Position",
"chromo" : "1",
"start" : 999901,
"stop" : 1001100
}]
}
答案 0 :(得分:1)
继续我们在上述评论中的讨论......
你需要正确地连接数组,即
[stop] + _source.biomarkers.collect{it.stop}
将创建一个包含[stop, bio[0].stop, bio[1].stop, etc]
的数组,然后我们可以获取该数组的max()
。
所以我建议这样的事情应该有用(虽然未经测试)
percent <= (([stop] + _source.biomarkers.collect{it.stop}).min() - ([start] + _source.biomarkers.collect{it.start}).max()) / ([length] +_source.biomarkers.collect{it.stop - it.start + 1}).max()