嵌套对象和聚合

时间:2015-09-09 08:31:38

标签: elasticsearch nested

我将此映射到我的ES数据库中,该数据库使用嵌套对象。

每个文档都是公司,并且有一个保存为嵌套对象的员工列表。 这是映射:

 "company": {
    "properties": {
        "company_name": {
           "type": "string"
        },

       "employee": {
          "properties": {
              "name": {
                 "type": "string"
               },
              "city": {
                 "type": "string"
              }
          },
          "type": "nested"
        }
      }
    }
  }
}

我有这两家公司:

Company A 
    [
    Smith, Dallas
    Mark, New York
    Smith, Houston
    ]

Company B 
    [
    Smith, Dallas
    Peter, New York
    Mary, Houston
    ]

也就是说,在不同的公司中可以找到相同的名称,并且在每个公司中都可以找到相同的名称。

我需要运行的查询应该是这个:

为所有姓名为Smith的员工汇总城市

我需要这样的答案:

City for employee Smith:
   Dallas:  2
   Houston: 1

记住员工是嵌套对象的列表,我不需要任何有关公司名称的信息。

0 个答案:

没有答案
相关问题