doc_count on aggregations doesn't match total hits

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

doc_count on aggregations doesn't match total hits

Ron Sher
Hi,

I've started to use aggregations and it works very fast and cool. But it seems to get the wrong doc_count as opposed to the total hits.

For example - here's a typical search I use (I got for it total hits - 111 and doc_count 1348) :
{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "service_id": "880"
              }
            },
            {
              "bool": {
                "must": {
                  "term": {
                    "status_group": "paying"
                  }
                }
              }
            }
          ]
        }
      }
    }
  },
  "aggregations": {
    "atts": {
      "nested": {
        "path": "string_attributes"
      },
      "aggregations": {
        "filter_atts": {
          "filter": {
            "term": {
              "string_attributes.key": "Sales Manager"
            }
          },
          "aggregations": {
            "values": {
              "terms": {
                "field": "string_attributes.value",
                "size": 0,
                "order": {
                  "_term": "asc"
                }
              },
              "aggregations": {
                "reversed": {
                  "reverse_nested": {},
                  "aggregations": {
                    "health": {
                      "terms": {
                        "field": "health"
                      }
                    },
                    "missing_health": {
                      "missing": {
                        "field": "health"
                      }
                    },
                    "avg_contract_value": {
                      "avg": {
                        "field": "contract_value"
                      }
                    },
                    "sum_contract_value": {
                      "sum": {
                        "field": "contract_value"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "avg_contract_value": {
      "avg": {
        "field": "contract_value"
      }
    },
    "sum_contract_value": {
      "sum": {
        "field": "contract_value"
      }
    }
  }
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAKHuyJpNLN8Zw7cQjFjTvQTpfrPLDkrhzBmEyFXApWYti1r1tQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: doc_count on aggregations doesn't match total hits

dadoonet
It sounds like you are using nested documents. I guess it comes from here.

--
David ;-)
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs


Le 6 sept. 2014 à 07:49, Ron Sher <[hidden email]> a écrit :

Hi,

I've started to use aggregations and it works very fast and cool. But it seems to get the wrong doc_count as opposed to the total hits.

For example - here's a typical search I use (I got for it total hits - 111 and doc_count 1348) :
{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "service_id": "880"
              }
            },
            {
              "bool": {
                "must": {
                  "term": {
                    "status_group": "paying"
                  }
                }
              }
            }
          ]
        }
      }
    }
  },
  "aggregations": {
    "atts": {
      "nested": {
        "path": "string_attributes"
      },
      "aggregations": {
        "filter_atts": {
          "filter": {
            "term": {
              "string_attributes.key": "Sales Manager"
            }
          },
          "aggregations": {
            "values": {
              "terms": {
                "field": "string_attributes.value",
                "size": 0,
                "order": {
                  "_term": "asc"
                }
              },
              "aggregations": {
                "reversed": {
                  "reverse_nested": {},
                  "aggregations": {
                    "health": {
                      "terms": {
                        "field": "health"
                      }
                    },
                    "missing_health": {
                      "missing": {
                        "field": "health"
                      }
                    },
                    "avg_contract_value": {
                      "avg": {
                        "field": "contract_value"
                      }
                    },
                    "sum_contract_value": {
                      "sum": {
                        "field": "contract_value"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "avg_contract_value": {
      "avg": {
        "field": "contract_value"
      }
    },
    "sum_contract_value": {
      "sum": {
        "field": "contract_value"
      }
    }
  }
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAKHuyJpNLN8Zw7cQjFjTvQTpfrPLDkrhzBmEyFXApWYti1r1tQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3A592117-5A62-4B5E-A1C3-E954C275E1FC%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: doc_count on aggregations doesn't match total hits

Ron Sher
So the doc count is for the nested documents?
what if I want to get the doc count of the "parent" docs? I guess I can use the total hits, right?

On Saturday, September 6, 2014 8:52:30 AM UTC+3, David Pilato wrote:
It sounds like you are using nested documents. I guess it comes from here.

--
David ;-)
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs


Le 6 sept. 2014 à 07:49, Ron Sher <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ZAaJJWxFM20J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">ron....@...> a écrit :

Hi,

I've started to use aggregations and it works very fast and cool. But it seems to get the wrong doc_count as opposed to the total hits.

For example - here's a typical search I use (I got for it total hits - 111 and doc_count 1348) :
{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "service_id": "880"
              }
            },
            {
              "bool": {
                "must": {
                  "term": {
                    "status_group": "paying"
                  }
                }
              }
            }
          ]
        }
      }
    }
  },
  "aggregations": {
    "atts": {
      "nested": {
        "path": "string_attributes"
      },
      "aggregations": {
        "filter_atts": {
          "filter": {
            "term": {
              "string_attributes.key": "Sales Manager"
            }
          },
          "aggregations": {
            "values": {
              "terms": {
                "field": "string_attributes.value",
                "size": 0,
                "order": {
                  "_term": "asc"
                }
              },
              "aggregations": {
                "reversed": {
                  "reverse_nested": {},
                  "aggregations": {
                    "health": {
                      "terms": {
                        "field": "health"
                      }
                    },
                    "missing_health": {
                      "missing": {
                        "field": "health"
                      }
                    },
                    "avg_contract_value": {
                      "avg": {
                        "field": "contract_value"
                      }
                    },
                    "sum_contract_value": {
                      "sum": {
                        "field": "contract_value"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "avg_contract_value": {
      "avg": {
        "field": "contract_value"
      }
    },
    "sum_contract_value": {
      "sum": {
        "field": "contract_value"
      }
    }
  }
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ZAaJJWxFM20J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">elasticsearc...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/elasticsearch/CAKHuyJpNLN8Zw7cQjFjTvQTpfrPLDkrhzBmEyFXApWYti1r1tQ%40mail.gmail.com?utm_medium=email&amp;utm_source=footer" target="_blank" onmousedown="this.href='https://groups.google.com/d/msgid/elasticsearch/CAKHuyJpNLN8Zw7cQjFjTvQTpfrPLDkrhzBmEyFXApWYti1r1tQ%40mail.gmail.com?utm_medium\75email\46utm_source\75footer';return true;" onclick="this.href='https://groups.google.com/d/msgid/elasticsearch/CAKHuyJpNLN8Zw7cQjFjTvQTpfrPLDkrhzBmEyFXApWYti1r1tQ%40mail.gmail.com?utm_medium\75email\46utm_source\75footer';return true;">https://groups.google.com/d/msgid/elasticsearch/CAKHuyJpNLN8Zw7cQjFjTvQTpfrPLDkrhzBmEyFXApWYti1r1tQ%40mail.gmail.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/774c45ee-6ded-4577-ab8b-e517844b34d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.