[英]Elasticsearch inline script filter not working
我正在嘗試在 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
}]
}
跟進我們在上述評論中的討論......
您需要正確連接數組,即
[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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.