2015-05-21 59 views
0

排序由外地的一些項目,其中一個條件匹配,別人比方說,我有這樣映射的文件:Elasticsearch:由另一個

{ 
    "corp" : { 
    "mappings" : { 
     "staff" : { 
     "properties" : { 
      "created" : { 
      "type" : "date", 
      "format" : "dateOptionalTime" 
      }, 
      "name" : { 
      "type" : "string" 
      }, 
      "public" : { 
      "type" : "boolean" 
      }, 
      "salary" : { 
      "type" : "long" 
      } 
     } 
     } 
    } 
    } 
} 

而且這樣的數據集:

[{"name": "John", "salary": 100000, "public": true, "created": "<datestamp>"}, 
{"name": "Bob", "salary": 80000, "public": false, "created": "<datestamp>"}, 
{"name": "Wendy", "salary": 110000, "public": true, "created": "<datestamp>"}, 
{"name": "Joan", "salary": 210000, "public": false, "created": "<datestamp>"}] 

我想要構建一種排序,這樣我們按工資只排序其中public=true,然後按created字段排序其餘項目。最終的結果應該是:

  1. 溫迪
  2. 約翰
  3. 鮑勃(取決於created日期)
  4. 瓊(取決於created日期)

這可能嗎?

回答

1

這應做到:

GET /corp/staff/_search 
{ 
    "sort": [ 
    { 
     "public": { 
     "order": "desc" 
     } 
    }, 
    { 
     "salary": { 
     "order": "asc" 
     } 
    }, 
    { 
     "created": { 
     "order": "asc" 
     } 
    } 
    ] 
}