嗨这是弹性搜索的样本输出
"table":{
"data":[
{
"label":"First Label",
"value":"10"
},
{
"label":"1st Label",
"value":"9"
}
],
"details":"Examples set on MSRP, your actual payment may vary based on price set by dealer."
}
我希望按升序排序,无论是通过colunm标签还是通过值。
我尝试的搜索选项是
sort = [{"data.label" : {"order" : "asc", "mode" : "min", "nested_path" : "data"}}];
sort = [{ "table.data": {"order": "asc"}]
但是,我没有得到预期的排序结果
对此的任何帮助将不胜感激
答案 0 :(得分:0)
查询的排序部分应为 -
"sort": { "label": { "order": "desc" }}
或
"sort": { "value": { "order": "desc" }}
或
"sort": [
{ "label": { "order": "desc" }},
{ "value": { "order": "desc" }}
]
以下是获取内部排序元素的映射,文档和后续查询。
PUT /table
{
"mappings": {
"data": {
"properties": {
"name": {"type": "string"},
"subjects": {
"type": "nested",
"properties": {
"name": { "type": "string"},
"marks":{ "type": "integer"}
}
}
}
}
}
}
PUT /table/data/1?pretty
{
"name":"Ram",
"subjects":[
{
"name":"English",
"marks":13
},
{
"name":"Hindi",
"marks":12
}
]
}
PUT /table/data/2?pretty
{
"name":"Sam",
"subjects":[
{
"name":"Biology",
"marks":83
},
{
"name":"Maths",
"marks":68
}
]
}
PUT /table/data/3?pretty
{
"name":"Jim",
"subjects":[
{
"name":"Chemistry",
"marks":96
},
{
"name":"Geology",
"marks":58
}
]
}
GET table/data/_search
{
"query":{
"nested":{
"path":"subjects",
"query": {
"match_all": {}
},
"inner_hits":{
"sort":{
"subjects.marks":{
"order":"asc"
}
}
}
}
}
}