2017-06-06 99 views
1

你好,這是我從彈性搜索彈性排序不工作

"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

查詢您的分類部分應是 -

"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" 
     } 
     } 
    } 
    } 
} 
} 
+0

我試過所有的組合,它不工作。我們應該去嵌套排序嗎? – Arjun

+0

你能否提出你正在製作的完整查詢! –

+0

請查詢網址 - /_search?q =「{」filtered「:{」filter「:{」bool「:{」must「:[{」ids「:{」values「:[」search_key「 ]}}}}「&sort = {」value「:{」order「:」asc「}} – Arjun