弹性搜索:对嵌套的细分应用过滤条件,仅返回那些细分

时间:2018-08-13 15:53:35

标签: java spring elasticsearch spring-data-elasticsearch

我有一个包含以下格式的Elastic Search订单的客户信息

{
  "_index": “customer_domain_r4",
  "_type": “CustomerData”,
  "_id": "6fff6ce8-e792-4047-b636-a1dda0aa2b72",
  "_version": 173,
  "_score": 3.551258,
  "_source": {
    “first”: "John",
    “last”: "Doe",
    “dateOfBirth”: null,
    "primaryPhone": "6154525131",
    “customerOrders”: [
      {
        “orders”: [
          {
            “orderNumber": 1,
            “orderName": “Grocery”,
            "recordVersion": 1,
            "createdDateTimeGmt": "May 09, 2018 03:19:11 PM",
            "deletedDateTimeGmt": "May 12, 2018 08:28:42 PM",
            "createdSessionTokenId": "PUWzJmipCIyvciMDEr3IfhXuV3Gx",
            "updatedSessionTokenId": "1234567890",
            "lastUpdatedDateTimeGmt": "May 12, 2018 08:28:48 PM",
            “orderType”: “Online”   
            "id": "8e2973e3-b43b-4430-b6d7-7c24846e9bba"
          },
          {
            “orderNumber": 2,
            “orderName": “Medications”,
            "recordVersion": 1,
            "createdDateTimeGmt": "May 09, 2018 03:19:11 PM",
            "deletedDateTimeGmt": null,
            "createdSessionTokenId": "PUWzJmipCIyvciMDEr3IfhXuV3Gx",
            "updatedSessionTokenId": "1234567890",
            "lastUpdatedDateTimeGmt": "May 12, 2018 08:28:48 PM",
            “orderType”: “Offline”  
            "id": "8e2973e3-b43b-4430-b6d7-7c2665e9bba"
          }
]
}

现在,我的要求是仅获取给定客户ID的某种类型的订单。我运行的查询

{"index":"customer_domain_r4","type":"CustomerData"}
{"query":{"bool":{"must":[{"match":{"id":"6fff6ce8-e792-4047-b636-a1dda0aa2b72"}},{"nested":{"path":"customerOrders","query":{"bool":{"must":[{"match":{"customerOrders. orderType":"Online"}}]}}}}]}},"_source":{"includes":["customerOrders"],"excludes":[]}}

上面的查询返回客户的所有订单,因为条件将查找具有在线订单类型的任何客户。我正在寻找仅返回在线类型的客户6fff6ce8-e792-4047-b636-a1dda0aa2b72的订单的查询。

有没有一种方法可以直接为包含部分添加条件。

如果不是,我必须在Java中间层部分对此进行过滤

0 个答案:

没有答案