提问要多花一点心思哦

es如何嵌套集合的部分查询

Elasticsearch | 作者 liushui00001 | 发布于2017年05月05日 | 阅读数:4346

1.对象
public class TestCompany
{
    private long comId;

    private String name;

    private String userName;

    private String phone;

    private List<TestEquip> equips;
}

2.
{
  "took": 11,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 4,
    "max_score": 1,
    "hits": [
      {
        "_index": "testindex",
        "_type": "testdoc02",
        "_id": "2",
        "_score": 1,
        "_source": {
          "name": "禅城大队",
          "comId": 2,
          "equips": [
            {
              "amount": 0.49699034416118526,
              "name": "灭火剂3"
            },
            {
              "amount": 0.9909861609988635,
              "name": "灭火剂4"
            },
            {
              "amount": 0.8921398533575954,
              "name": "灭火剂5"
            },
            {
              "amount": 0.3477874444278789,
              "name": "灭火剂6"
            },
            {
              "amount": 0.4694732280478692,
              "name": "灭火剂7"
            },
            {
              "amount": 0.5693896502757985,
              "name": "消防锤2"
            },
            {
              "amount": 0.6446930199027758,
              "name": "消防锤3"
            },
            {
              "amount": 0.7851977178885842,
              "name": "消防锤4"
            },
            {
              "amount": 0.15137973307778096,
              "name": "消防锤5"
            },
            {
              "amount": 0.12135203530207805,
              "name": "消防锤6"
            }
          ],
          "userName": "郭武斌洪"
        }
      },
      {
        "_index": "testindex",
        "_type": "testdoc02",
        "_id": "4",
        "_score": 1,
        "_source": {
          "name": "大沥中队",
          "comId": 4,
          "equips": [
            {
              "amount": 0.45752216339077545,
              "name": "灭火剂14"
            },
            {
              "amount": 0.9573554797963816,
              "name": "灭火剂15"
            },
            {
              "amount": 0.28037080153172733,
              "name": "灭火剂16"
            },
            {
              "amount": 0.9255136559693374,
              "name": "灭火剂17"
            },
            {
              "amount": 0.9726597458279264,
              "name": "灭火剂18"
            },
            {
              "amount": 0.5956327265413587,
              "name": "消防锤13"
            },
            {
              "amount": 0.30506822109184917,
              "name": "消防锤14"
            },
            {
              "amount": 0.04905408396973221,
              "name": "消防锤15"
            },
            {
              "amount": 0.9138944972488922,
              "name": "消防锤16"
            },
            {
              "amount": 0.6839140705711093,
              "name": "消防锤17"
            }
          ],
          "userName": "马飞鹏"
        }
      },
      {
        "_index": "testindex",
        "_type": "testdoc02",
        "_id": "1",
        "_score": 1,
        "_source": {
          "name": "佛山洪消防支队",
          "comId": 1,
          "equips": [
            {
              "amount": 0.7220096548596434,
              "name": "灭火剂0"
            },
            {
              "amount": 0.19497605734770518,
              "name": "灭火剂1"
            },
            {
              "amount": 0.6671595726539502,
              "name": "灭火剂2"
            },
            {
              "amount": 0.7784408674101491,
              "name": "灭火剂3"
            },
            {
              "amount": 0.6186076060240648,
              "name": "灭火剂4"
            },
            {
              "amount": 0.62309699131219,
              "name": "消防锤0"
            },
            {
              "amount": 0.23675163488485773,
              "name": "消防锤1"
            },
            {
              "amount": 0.48722715836911057,
              "name": "消防锤2"
            },
            {
              "amount": 0.6804221244148292,
              "name": "消防锤3"
            },
            {
              "amount": 0.524545450315388,
              "name": "消防锤4"
            }
          ],
          "userName": "李成龙"
        }
      },
      {
        "_index": "testindex",
        "_type": "testdoc02",
        "_id": "3",
        "_score": 1,
        "_source": {
          "name": "南海大队",
          "comId": 3,
          "equips": [
            {
              "amount": 0.41324284503792297,
              "name": "灭火洪剂11"
            },
            {
              "amount": 0.28672630466619475,
              "name": "灭火洪剂12"
            },
            {
              "amount": 0.6246190087763299,
              "name": "灭火洪剂13"
            },
            {
              "amount": 0.7314622835577995,
              "name": "灭火洪剂14"
            },
            {
              "amount": 0.48603697468545926,
              "name": "灭火洪剂15"
            },
            {
              "amount": 0.15212608417031703,
              "name": "消防锤9"
            },
            {
              "amount": 0.029587621794166963,
              "name": "消防锤10"
            },
            {
              "amount": 0.4213153656782799,
              "name": "消防锤11"
            },
            {
              "amount": 0.4499815467962863,
              "name": "消防锤12"
            },
            {
              "amount": 0.2681778072406755,
              "name": "消防锤13"
            }
          ],
          "userName": "陈家俊"
        }
      }
    ]
  }
}

3.查询业务:查询南海大队下面的“消防锤”装备;也就是说查询TestCompany对象的equips中的一部分数据!!!

4.经过我的测试:_source、_all、store特性实现不了!!!!!!

急切 希望 大神指点  !!!!!
已邀请:

要回复问题请先登录注册