我们尝试聚合它返回所有文档的最小值。
我们有什么方法可以从每个文档中找到开始日期的最小值,比如使用elasticsearch吗?
输出应为“1989-03-01T00:00:00Z”:
{
"experience": [{
"isCurrent": false,
"endDate": "2000-06-01T00:00:00Z",
"jobTitle": "a",
"company": "a",
"title": "a",
"startDate": "1996-05-01T00:00:00Z"
}, {
"isCurrent": false,
"endDate": "2012-01-01T00:00:00Z",
"jobTitle": "b",
"company": "B",
"title": "b",
"startDate": "2008-01-01T00:00:00Z"
}, {
"isCurrent": false,
"endDate": "2007-10-01T00:00:00Z",
"company_org": "",
"jobTitle": "c",
"company": "C",
"companyUrl": "",
"title": "c",
"startDate": "2004-09-01T00:00:00Z"
}, {
"isCurrent": false,
"endDate": "1993-03-01T00:00:00Z",
"jobTitle": "d",
"company": "D",
"title": "d",
"startDate": "1991-05-01T00:00:00Z"
}, {
"isCurrent": false,
"endDate": "1991-05-01T00:00:00Z",
"company_org": "",
"jobTitle": "e",
"company": "E",
"companyUrl": "",
"title": "e",
"startDate": "1989-03-01T00:00:00Z"
}]
}
答案 0 :(得分:1)
如果您的experience
字段具有nested
数据类型,那么您可以使用以下带有nested
inner_hits
的查询检索您所期望的内容:
{
"query": {
"nested": {
"path": "experience",
"query": {
"query_string": { "query": "*" }
},
"inner_hits": {
"size": 1,
"sort": { "startDate": "asc" }
}
}
}
}
这将为您提供experience
具有最早startDate