Background_filter on parent field in a nested significant_terms aggregation

My mapping looks like:

"properties": {
  "user_id": {
    "type": "keyword"
  },
  "need_to_check": {
    "type": "boolean"
  },
  "tags": {
    "type": "nested",
    "properties": {
      "name": {
        "type": "keyword"
      },
      "relevance": {
        "type": "scaled_float",
        "scaling_factor": 100
      }
    }
  }
}

I would like to do significant_terms aggregation on tags.name and background_filter on need_to_check, but the following query won't do, because in the nested aggregation, I only have the access to the tags documents, which don't have the need_to_check field. As a result, in the response, the bg_counts in buckets are always 0.

GET index_xyz/_search
{  
  "size":0,
  "query":{  
    "bool":{  
      "filter":[  
        {  
          "terms":{  
            "userid":[  
              "1",
              "2"
            ]
          }
        },
        {  
          "term":{  
            "need_to_check":false
          }
        }
      ]
    }
  },
  "aggs":{  
    "nested":{  
      "nested":{  
        "path":"tags"
      },
      "aggs":{  
        "tags":{  
          "significant_terms":{  
            "field":"tags.name",
            "background_filter": {
              "term":{  
                "need_to_check":false
              }
            }
          }
        }
      }
    }
  }
}

What's the right way to achieve this? Thanks.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.