ELASTICSEARCH-仅汇​​总到查询结果

时间:2020-08-17 14:57:15

标签: elasticsearch

我想首先过滤包含以下内容的结果:嵌套描述和门字段中的33和芝加哥

{
  "query": {
    "nested": {
      "path": "data.addresses",
      "inner_hits": {
        "_source": ["data.addresses.direction"],
        "size":100
      },
      "query": {
        "nested": {
          "path": "data.addresses.services",
          "inner_hits": {
        "size":100
      }, 
      "query": {
        "bool": {
          "should": [
              {"match": {"data.addresses.services.description": "chicago"}},
              {"term": { "data.addresses.services.door.keyword": "33"}}
              ]
            }
          }
        }
      }
    }
  },
  "aggs": {
    "NAME": {
      "nested": {
        "path": "data.addresses"
      },
      "aggs": {
        "NAME": {
          "terms": {
            "field": "data.addresses.directions",
            "size": 10
          }
        }
      }
    }
  }
}

然后,我想获取有关路线字段的查询结果的计数器,但是它返回整个JSON的计数器。

如何仅对查询结果进行汇总?

映射

{
  "miguel" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "created_at" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "data" : {
          "type" : "nested",
          "properties" : {
            "addresses" : {
              "type" : "nested",
              "properties" : {
                "description" : {
                  "type" : "text"
                }
                "services" : {
                  "type" : "nested",
                  "properties" : {
                    "banner" : {
                      "type" : "text",
                      "fields" : {
                        "keyword" : {
                          "type" : "keyword",
                          "ignore_above" : 256
                        }
                      }
                    },
                    "description" : {
                      "type" : "text",
                      "fields" : {
                        "keyword" : {
                          "type" : "keyword",
                          "ignore_above" : 256
                        }
                      }
                    },
                    "output" : {
                      "type" : "text",
                      "fields" : {
                        "keyword" : {
                          "type" : "keyword",
                          "ignore_above" : 256
                        }
                      }
                    },
                    "door" : {
                      "type" : "text",
                      "fields" : {
                        "keyword" : {
                          "type" : "keyword",
                          "ignore_above" : 256
                        }
                      }
                    }                  
                  }
                }
              }
            }  
          }
        }
      }
    }
  }
}

0 个答案:

没有答案