【发布时间】:2017-01-09 13:00:57
【问题描述】:
在我的 ElasticSearch (2.x) 上,我有这样的文档:
{
"title": "A good title",
"formats": [{
"name": "pdf",
"prices": [{
"price": 11.99,
"currency": "EUR"
}, {
"price": 18.99,
"currency": "AUD"
}]
}]
}
我想按formats.prices.price 对文档进行排序,但仅限formats.prices.currency === 'EUR' 的位置
我尝试在 formats.prices 上做一个嵌套字段,然后运行这个查询:
{
"query": {
"filtered": {
"query": {
"and": [
{
"match_all": {}
}
]
}
}
},
"sort": {
"formats.prices.price": {
"order": "desc",
"nested_path": "formats.prices",
"nested_filter": {
"term": {
"currency": "EUR"
}
}
}
}
}
但不幸的是,我无法得到正确的订单。
更新: 映射的相关部分:
"formats": {
"properties": {
"name": {
"type": "string"
},
"prices": {
"type": "nested",
"include_in_parent": true,
"properties": {
"currency": {
"type": "string"
},
"price": {
"type": "double"
}
}
}
}
},
【问题讨论】:
标签: sorting elasticsearch nested