0
排序我ElasticSearch(2.x的)我有這樣的文件:Elasticsearch如何使用條件
{
"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"
}
}
}
}
}
但不幸的是,我不能得到正確的順序。
UPDATE:映射 有關部分:
"formats": {
"properties": {
"name": {
"type": "string"
},
"prices": {
"type": "nested",
"include_in_parent": true,
"properties": {
"currency": {
"type": "string"
},
"price": {
"type": "double"
}
}
}
}
},
都能跟得上。它似乎將所有貨幣重寫爲「歐元」,訂單不正確。 –
你能給我你的映射嗎? – blackmamba
「屬性」:{ 「格式」:{ 「類型」: 「嵌套」, 「屬性」:{ 「名稱」:{ 「類型」: 「串」 }, 「價格」:{ 「類型」: 「嵌套」, 「屬性」:{ 「價格」:{ 「類型」: 「雙」 }, 「貨幣」:{ 「類型」: 「串」 } } } } }, 「title」:{ 「type」:「string」 } } – blackmamba