Elasticsearch滤波器按属性计数的数字计数,其价值小于数字
我有一个结构化的索引,就像
{
"took": 301,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4270,
"relation": "eq"
},
"max_score": 2.0,
"hits": [
{
"_index": "asset_revision_structured_data",
"_type": "_doc",
"_id": "2931293",
"_score": 2.0,
"_source": {
"doc": {
"prediction": {
"drugs": {
"document_metadata": {},
"predictions": {
"relevant_drugs": [
{
"confidence_score": 0.9946682341655051
}
]
}
}
}
}
}
}
]
}
}
我想过滤结果一样返回所有 hits
,其中50%或更多相关_DRUGS
具有 profest> profeste> profest> profess_score
&lt ; 0.6。
我知道,这将使我在包含 a seacteant_drugs
条目的情况下给我所有的命中。 0.6:
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "doc.prediction.drugs"
}
},
{
"range": {
"doc.prediction.drugs.predictions.relevant_drugs.confidence_score": {
"lt": 0.6
}
}
}
]
}
},
"_source": ["doc.prediction.drugs"]
}
但是我只想返回该子句适用于 seconcess_drugs
的一半以上的命中。我该怎么做?
谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
tldr;
我不相信
elasticsearch
有一个特定的查询。但是您可以使用 runtime fields 我可以将过滤器应用于一个字段。
在这里重现的
查询以下的数据
是我用来运行测试以求解
,其中一个运行时字段在您的文档中获得了所有信心_score的中位数。
然后过滤以低置信度得分。
Tldr;
I don't believe
Elasticsearch
has a specific query to do so.But you can use Painless. It allow for scripted behaviour in your queries. I also leverage the RuntimeFields to create on the fly a field I can apply a filter to.
To Reproduce
Here is the data I used to run my tests
To Solve
Below the query, with a runtime field getting the median of all the confidence_score in your documents.
And then filtering for low confidence score.