# Search by sum of nested objects

**URL:** https://discuss.elastic.co/t/search-by-sum-of-nested-objects/356621
**Category:** Elasticsearch
**Created:** [April 2, 2024, 2:46pm UTC](https://discuss.elastic.co/t/search-by-sum-of-nested-objects/356621 "2024-04-02T14:46:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![pikorro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pikorro/32/133193_2.png) [@pikorro](https://discuss.elastic.co/u/pikorro)
#### Post date: [April 2, 2024, 2:46pm UTC](https://discuss.elastic.co/t/search-by-sum-of-nested-objects/356621/1 "2024-04-02T14:46:17Z")

</div>

I have list of docs with following struct:

```auto
{
  "name": "John Doe",
  "work_experiences": [
    {
      "company": "Accenture",
      "duration": 24
    },
    {
      "company": "IBM",
      "duration": 36
    }
  ]
}

```

```auto
curl -X PUT "localhost:9200/testing?pretty" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "properties": {
      "name": { "type": "text" },
      "work_experiences": {
        "type": "nested",
        "properties": {
          "company": { "type": "text" },
          "duration": { "type": "integer" }
        }
      }
    }
  }
}
'

curl -X POST "localhost:9200/testing/_doc" -H 'Content-Type: application/json' -d '
{
  "name": "John Doe",
  "work_experiences": [
    {
      "company": "Accenture",
      "duration": 24
    },
    {
      "company": "IBM",
      "duration": 36
    }
  ]
}
'

curl -X POST "localhost:9200/testing/_doc" -H 'Content-Type: application/json' -d '
{
  "name": "Jane Smith",
  "work_experiences": [
    {
      "company": "Accenture",
      "duration": 18
    },
    {
      "company": "Google",
      "duration": 42
    },
    {
      "company": "Accenture",
      "duration": 30
    }
  ]
}
'

```

```auto

I want to list all profiles that were working in total at least 40 months in companies with wildcard match *accent* in company name

```

In mentioned case Jane Smith was working in total 48 monts in accenture. However I have trouble composing query, I was trying script, aggregations etc. On top of that tere are few other conditions but in general question is about filtering by aggregated sum of nested objects

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 30, 2024, 2:46pm UTC](https://discuss.elastic.co/t/search-by-sum-of-nested-objects/356621/2 "2024-04-30T14:46:41Z")

</div>

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