1

I have this mapping:

...

[products_categories_id] => Array
(
    [type] => object
) 

...

With this set of data:

          "products_categories_id": [
        {
          "id": 164,
          "value": "Flight Case e Accessori - Supporti per Chitarra e Basso",
          "singular_value": "Flight Case e Accessorio - Supporto per Chitarra e Basso"
        },
        {
          "id": 443,
          "value": "Chitarre - Supporti per Chitarra",
          "singular_value": "Chitarra - Supporto per Chitarra"
        },
        {
          "id": 450,
          "value": "Bassi - Accessori per Basso - Supporti per Basso",
          "singular_value": "Basso - Accessorio per Basso - Supporto per Basso"
        }
      ]

And this is the total of product finded:

"hits": {
  "total": 67,

When I aggregate the result of my search, the number of aggregation not is correct, because the engine return the number of my category and the number of categories existend in within object with my finded category(443)

This is the aggregation section:

  "aggs": {

"filter_category": {
  "terms": {
    "script": "doc['products_categories_id.id'].value",
    "size": "20",
    "order": {
      "max_score": "desc"
    }
  },
  "aggs": {
    "max_score": {
      "max": {
        "script": "_score"
      }
    }
  }
}

}

And this is the results of query:

  "aggregations": {
"filter_category": {
  "doc_count_error_upper_bound": 0,
  "sum_other_doc_count": 0,
  "buckets": [
    {
      "key": "443",
      "doc_count": 24,
      "max_score": {
        "value": 62.1923942565918
      }
    },
    {
      "key": "164",
      "doc_count": 40,
      "max_score": {
        "value": 50.844512939453125
      }
    },
    {
      "key": "65",
      "doc_count": 2,
      "max_score": {
        "value": 41.21534729003906
      }
    },
    {
      "key": "153",
      "doc_count": 1,
      "max_score": {
        "value": 30.362688064575195
      }
    }
  ]
}

}

I expect this results:

{
"key": "443",
"doc_count": 67,
"max_score": {
"value": 62.1923942565918
}

Someone can help me, thanks :)

Lib3Ns
  • 11
  • 2
  • Is 67 the total number of docs in the index? Can you post the complete mapping? – sramalingam24 Apr 26 '18 at 12:24
  • No, 67 is the result of filterered query with this filter: "query": { "bool": { "filter": { "bool": { "must": [ [{ "term": { "products_status": 1 } }, { "term": { "products_categories_id.id": "443" } }] ] } }, }, – Lib3Ns Apr 26 '18 at 13:06

0 Answers0