我刚刚发现了弹性搜索,我试图进行初步查询。例如在我的情况下,每篇文章有几个价格,我想按最低价格对这些文章进行排序。因此我不会考虑其他的。这只是我的文章排序的最低价格 这是我的文章:
{
"name": "john",
"prices": [
{
"price": "22"
},
{
"price": "28"
},
{
"price": "8"
}
]
},
{
"name": "peter",
"prices": [
{
"price": "7"
},
{
"price": "5"
},
{
"price": "2"
}
]
},
{
"name": "billy",
"prices": [
{
"price": "15"
},
{
"price": "17"
}
]
}
答案 0 :(得分:1)
POST /_search
{
"query" : {
"match_all": {}
},
"sort" : [
{
"prices.price": {
"order": "asc",
"mode" : "min"
}
}
]
}
注意:如果您的prices
个对象属于nested
类型(而不是object
),那么您还需要在"nested_path": "prices"
内添加prices.price
。
有关排序的更多信息,请点击此处: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html