ELASTICSERCH-Inner_hits汇总 [英] ELASTICSERCH - Inner_hits aggregations

查看:76
本文介绍了ELASTICSERCH-Inner_hits汇总的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试汇总{"wildcare":{"data.addresses.ces.cp":"maria *"},{"macth":{"data.addresses.ces.direction":"rodriguez"}}字段,但不会返回查询结果.

I am trying to do an aggregation of the {"wildcare": {"data.addresses.ces.cp": "maria*"}, {"macth": { "data.addresses.ces.direction": "rodriguez"}} fields, but it does not return the results of the query.

{ "_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?

How can I perform an aggregation that returns the values ​​of the query, and not all the values ​​of the JSON? In case the aggregations don't support inner_hits, how could I get wildcare and macth in aggs?

推荐答案

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

You need to repeat the filter conditions in the aggregation part so that the aggregation only runs on the selected nested documents:

{
  "_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"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

这篇关于ELASTICSERCH-Inner_hits汇总的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆