首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ELASTICSERCH - Inner_hits聚合

问ELASTICSERCH - Inner_hits聚合
EN

Stack Overflow用户
提问于 2020-08-26 22:37:24
回答 1查看 57关注 0票数 0

我尝试对{"wildcare":{"data.addresses.ces.cp":"maria*"},{"macth":{ "data.addresses.ces.direction":"rodriguez"}}字段进行聚合,但它没有返回查询结果。

代码语言:javascript
复制
{ "_source": "created_at",
      "size": 1, 
      "sort": [
        {
          "created_at.keyword": {
            "order": "desc"
          }
        }
      ], 
      "query": {
        "nested": {
          "path": "data.addresses",
          "inner_hits": {
          },
          "query": {
            "nested": {
              "path": "data.addresses.ces",
              "query": 
                  {"wildcare": {"data.addresses.ces.cp": "maria*"},
                  {"macth": { "data.addresses.ces.direction": "rodriguez"}}
              }
            }
          }
        }
      }

如何执行返回查询的值​​而不是JSON的所有值​​的聚合?如果聚合不支持inner_hits,我如何在aggs中获得wildcare和macth?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-26 23:02:18

您需要在聚合部件中重复过滤条件,以便仅在选定的嵌套文档上运行聚合:

代码语言:javascript
复制
{
  "_source": "created_at",
  "size": 1,
  "sort": [
    {
      "created_at.keyword": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "nested": {
      "path": "data.addresses",
      "inner_hits": {},
      "query": {
        "nested": {
          "path": "data.addresses.ces",
          "query": {
            "bool": {
              "filter": [
                {
                  "wildcard": {
                    "data.addresses.ces.cp": "maria*"
                  }
                },
                {
                  "match": {
                    "data.addresses.ces.direction": "rodriguez"
                  }
                }
              ]
            }
          }
        }
      }
    }
  },
  "aggs": {
    "addresses": {
      "nested": {
        "path": "data.addresses"
      },
      "aggs": {
        "ces": {
          "nested": {
            "path": "data.addresses.ces"
          },
          "aggs": {
            "query": {
              "filter": {
                "bool": {
                  "filter": [
                    {
                      "wildcard": {
                        "data.addresses.ces.cp": "maria*"
                      }
                    },
                    {
                      "match": {
                        "data.addresses.ces.direction": "rodriguez"
                      }
                    }
                  ]
                }
              },
              "aggs": {
                "cp": {
                  "terms": {
                    "field": "data.addresses.ces.cp"
                  }
                },
                "direction": {
                  "terms": {
                    "field": "data.addresses.ces.direction"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63600024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档