Elasticsearch:按给定映射中的最大字段值进行筛选

Elasticsearch:按给定映射中的最大字段值进行筛选,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,关于此Elasticsearch映射 PUT /some-index/_mapping/some-mapping { "properties": { "group-id": { "type": "keyword" }, "id": { "type": "keyword" }, "some-other-field": { "type": "keyword" } } } 假设我们有这样的价值观 [ {

关于此Elasticsearch映射

PUT /some-index/_mapping/some-mapping
{
  "properties": {
    "group-id": {
      "type": "keyword"
    },
    "id": {
      "type": "keyword"
    },
    "some-other-field": {
      "type": "keyword"
    }
  }
}
假设我们有这样的价值观

[
  { "group-id": "1", "id": "1", "some-other-field": "some" },
  { "group-id": "2", "id": "2", "some-other-field": "other" },
  { "group-id": "2", "id": "3", "some-other-field": "field" }
]
尝试生成查询


返回具有最大group-id的所有记录。在此特定示例中,它应准确返回最后2项,包括id和其他一些字段。当然,随着新记录被索引,最大的组id可能会变得更大。如果出现这种情况,则应返回一组全新的结果,因为以前的结果不再包含最大的组id。

如果需要支持最大的id,则应将字段类型更改为数字


您可以使用
max
聚合首先找出最大值(如果这是一个数字字段),然后执行第二个查询,搜索具有该最大值的所有文档(不要害怕执行多个查询来回答您的问题,这是非常好的)。

是否执行“[{”组id:“1”,“id:“1”其他字段“:“some”},{“group id”:“2”,“id”:“2”,“some other field”:“other”},{“group id”:“2”,“id”:“3”,“some other field”:“field”}]”,是单弹性文档,是嵌套字段吗?它们是3个不同的文档。您说在一次调用中无法做到这一点吗?的确,不是在我的头上。这是我正在弄清楚的,因此问题。。。虽然如此强大的工具中没有这样的基本功能,但感觉很奇怪。谢谢你的帮助!