我有这样一个Map,实际上是一个很大的文档,为简洁起见,排除了许多字段
{
"items": {
"mappings": {
"dynamic": "false",
"properties": {
"id": {
"type": "keyword"
},
"costs": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"costs_samples": {
"type": "flattened"
}
}
}
}
}
}
}
costs_samples
是可能成本的平坦场类型的巨大集合(有时超过10 k个条目)。必须强调costs_sample
不能位于costs
之外,因为在查询时,costs
中的一些conditions
应该与should
或match
子句组合在一起,比如(costs.country=this_value AND some_other costs_samples_condition
。我希望能够在costs
级别提取并最终注入一个新字段作为运行时字段,然后使用该字段进行排序、过滤和聚合。
{
"runtime_mappings": {
"costs.selected_cost": {
"type": "long",
"script": {
"source":
"for (def cost : doc['costs.costs_samples']) { if(cost.values!= null) {emit(Long.parseLong(cost.values.some_dynamic_identity_known_at_query_time.last))} }"
}
}
},
"query":{
"nested": {
"path": "costs",
"query": {
"bool": {
"filter": [
{
"terms": {
"costs.id": ["id-1","id-2"]
}
},
{
"term": {
"costs.selected_cost": 10
}
}
]
}
}
}
},
"fields": ["costs.selected_cost"]
}
问题是selected_cost
它不是由ES创建/返回的。没有错误消息。我哪里做错了?文档没有帮助。也许值得一提的是,我也尝试了两个不同的文档,如items
和costs
,然后执行某种连接操作,但性能测试真的很差。谢谢!
1条答案
按热度按时间jaql4c8m1#
长话短说,没有办法在嵌套字段类型中使用运行时字段。